This question already has answers here:
Closed 10 years ago.
At the moment I'm using bat file to launch my jar and set the java.system.class.loader. Is it possible to do this programmatically to get rid of the bat file?
You can't, because the system class loader is used before the first line of your program is executed.
You may use a different class loader for some classes, but you can't change the system class loader from your running program.
Related
This question already has answers here:
Why do my java files look strange in Eclipse?
(5 answers)
Closed 1 year ago.
I have two class .java but in pdcController.java I cannot do anything:
Look the image:
Look the icon are different in BandoService works all, but in .pdfController I cannot do anything (for example I cannot suggest for method or error import). pdfController and BandoServiceare in the same project.
This is not the source file, check the file path, you're probably not in the correct package.
I guess you have several modules in your maven project and you opened the file from the parent module.
If you see the file only in the parent module it's time to git fetch.
This question already has answers here:
How to read text file from classpath in Java?
(17 answers)
Closed 3 years ago.
I want to read the configuration file outside the jar, how should I do?
I tried classloader.getResourceAsStream("config.xml") and succeeded while I am running the code inside Intellij. Now I want to build the jars to a folder and place the config.xml under the same folder, not inside the jar, but the program fails to detect the config.xml.
Is there a graceful way of reading the config.xml instead of using File with relative path in the code, which doesn't work while debugging/running inside the IDE?
Yes, turn it into a system property, and provide it to anything running any Java process/application.
Let's say you have a config.xml file located inside /some/path/down/the/line/, then you can do: java --classpath ... -Dapp.config=/some/path/down/the/line/config.xml tld.domain.Application.
Then all you have to do in your Java code is to reference that name/path: final String configFile = System.getProperty("app.config");, and use any well-known routine to read it from there.
Basically, you have to make sure the file/path/location is provided somehow to the Java classpath.
This question already has answers here:
Execute another jar in a Java program
(7 answers)
Closed 5 years ago.
I am having the java main application which needs to execute another jar file and return it without waiting for the jar execution complete. Is it possible to achieve it using Java. Can anyone give some inputs in it.
Do following:
Runtime.getRuntime().exec("java -jar <PATH_OF _JAR>");
in your Main class.
And as #Yoav has suggested. You need to take care of errors by adopting proper error handling strategy.
Do Read - https://www.tutorialspoint.com/java/lang/runtime_exec.htm
This question already has answers here:
How to add resources to classpath
(3 answers)
What is a classpath and how do I set it?
(10 answers)
Closed 5 years ago.
I'm on a new branch of a git project on which I've made my own config file called MY_NAME.conf which is located in
Users/myname/IdeasProject/projectName/src/main/resources/config.
However, I'm having some issues getting my branch to run. So, just to make sure things are smooth I set up a new environment and I've cloned into the master. This is all done at
Users/myproject
However, now when I try to run the project I get a message
java.io.IOException: resource not found on classpath:
config/MY_NAME.conf
Why is it looking for this file at all? And even if it is, why is it not finding MY_NAME.conf?
Consider setting the classpath through one of these recommended techniques. Without knowing the specifics of your runtime environment, there should be a mechanism provided to include src/main/resources in your java classpath.
I think the issue is that classpath doesnt include conf folder.
You can modify/set class path with: set CLASSPATH=path1;path2
This question already has answers here:
"The public type <<classname>> must be defined in its own file" error in Eclipse [duplicate]
(8 answers)
Closed 6 years ago.
Start. Applet not initialized. My source code doesn't have any "bugs", but I am still unable to successfully run and compile the source code on Eclipse. How do I get the source code to successfully run and compile on Eclipse?
You have a made a common error, often situated with novice Java programmers. You have a class named ConvertCelsiusToFahrenheit, but the name of the file isn't the same. Remember, that one Java class is allowed per file (unless if nested or not public), and the file must have the same name as the class. See the question for why a file must me named as its class