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
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:
Read properties file outside JAR file
(8 answers)
Closed 6 years ago.
As stated in spring-boot-reference:
On your application classpath (e.g. inside your jar) you can have an
application.properties that provides a sensible default property value
for name. When running in a new environment, an application.properties
can be provided outside of your jar that overrides the name
I place a duplicated application.properties with overridden name on the same path as jar file, however when running the application with:
java -jar target/myproject-0.0.1-SNAPSHOT.jar
The name value is not overridden, it still refers to the one inside application.properties inside jar file. I also tried:
java -Dspring.config.location=/target/application.properties -jar target/myproject-0.0.1-SNAPSHOT.jar
But it does not work, please help.
Edit
When I change the current directory to target and run it, it works.
java -jar myproject-0.0.1-SNAPSHOT.jar
Why? Why cannot be outside the path and run it?
It doesn't work because you are trying to launch the jar from another folder: spring boot looks for files/folder relative your current folder.
You can:
1) copy application.properties either in ./ or ./config/, relative to your current folder.
2) Or specify -Dspring.config.location:
$ java -Dspring.config.location=target/application.properties -jar target/myproject-0.0.1-SNAPSHOT.jar
You spelt config as conig, should work if you spell it right.
This question already has answers here:
Changing the current working directory in Java?
(14 answers)
Closed 7 years ago.
I have an eclipse rcp application, which i am launching by setting the working directory in the arguments tab of the debug configuration.
Meanwhile i needed to change the current working directory upon application start.
I've tried the following options : System.setProperty("user.dir", this.strDestination);
But it doesn't work if we use relative file path, as it refers to the older working directory. Only solution that is working in this regard is using getAbsoluteFile or getAbsolutePath (which is not a feasible option as relative paths is used in a number of location).
Any approach in this regard is highly appreciated.
I'm pretty sure you can't modify the current process' working directory. Instead you can use the File(String, String) constructor which creates a new File instance from a parent pathname string and a child pathname string.
Is your this.strDestination variable an absolute path?
According to this answer, you should use an absolute path in System.setProperty for the "user.dir" changes to take effect.
Note: I didn't have enough rep to add a comment. Hence adding as an answer.
This question already has answers here:
"R cannot be resolved to a variable"? [duplicate]
(30 answers)
Closed 2 years ago.
I cannot fix:
"R cannot be resolved to a variable"
I have tried cleaning, building, I have deleted and made sure that any "java.R" imports are missing or whatever but I STILL cannot seem to squash the bugger!
Any reference to id's or layouts don't work and it just feeds back an error.
Do any of the files in your resource folders have capital letters in them? Capital letters aren't allowed.
This hung me up once....
Try the following things:
Make sure none of the XML files (menus, layouts, etc.) has any errors. Those prevent the R fropm being genreated
Delete the project from eclipse and import it again
Look for Android meta data files (i think those are in a .android folder) and delete those
hth..
Try the below steps to resolve the issue,It worked for me:
Cleaning the project and then building it again. Closing project and
then opening it again.
Closing project and then opening it again.
Going to Project Properties > Java Build Path > Tick Android Version Checkbox
ensure no errors in XML files,Because errors in xml file Prevents the R.jave file to be created.
try downloading the latest version of android SDK,if available.