I am trying to access a properties file from within a jar file ... InputStream is = getClass().getResourceAsStream("rehydration.properties"); and throw the following error (one of my own)- Wed Aug 13 15:59:59 BST 2003 : Can't read the importer.properties file. Make sure rehydration.properties is in the right place. Basically I can't find the resource file that I would like to be external to the jar file and in the same directory. Is there a standard solution to this, or any good articles here I could refer to? Many thanks in advance Andrew
getResourceAsStream() (Actually all the ClassLoader getResource methods) actually searches the classpath. If you don't want rehydration.properties in the jar, to use the ClassLoader, you muyst put it in a directory specified in the classpath.
Thanks Carl, But ... I am afraid that didn't work for me. I still can't find the resource file - I've placed it in the same directory as the JAR file and tried both java -jar -classpath ./ XMLCandidateRehydration.jar and java -jar -classpath e:\testing\ XMLCandidateRehydration.jar and neither finds the properties file. Is there an alternative to getResourceAsStream() to read in the properties file? Thanks again. Andrew
Originally posted by Carl Trusiak: getResourceAsStream() (Actually all the ClassLoader getResource methods) actually searches the classpath. If you don't want rehydration.properties in the jar, to use the ClassLoader, you muyst put it in a directory specified in the classpath.
Indeed. If you use the "-jar" option, the -classpath option is ignored. Executable jar files are expected to be self-contained (except for things loaded by the boot class loader). If you want to do this, then you'll have to use the class name of the main class in the jar file on the command line: java -classpath XMLCandidateRehydration.jar;. com.me.MyClass