I have some jar files that need to read files at startup. These files are located in directories next the jar files. This is how my directory listing looks like:
code.jar
config/
confifile.cfg
Then, in a command line prompt, I set the classpath as:
set CLASSPATH=./ext/*;./*
Then I run the program but it keeps complaining that it cannot find the “configfile.cfg”.
/config/configfile.cfg file not found!
This error comes from this code:
try {
r = new BufferedReader(new FileReader((String)botinfilename));
fileName=(String)botinfilename;
}
catch (FileNotFoundException e) {
System.err.println(botinfilename + " is not found");
}
I noticed it works if I put the /config directory inside the jar file. But if I remove it and put it next to the jar it does not find the config file.
Is there some java setting trick to make this work?
EDIT 1:
I launch my program like this:
java StartProgram
To keep it short, I just added the “-cp” JVM option. My problem was I need to add the root directory (where my jars and resources are located) to my classpath. Previously I had just added the jars with the * wildcard.
or you can set the class path