I am trying to read the an xml configuration from a jar file deployed to dm-server
here is the code
Reader fileReader = null;
try {
fileReader = new FileReader("test.xml");
} catch (FileNotFoundException fnfex) {
fnfex.printStackTrace();
} catch (IOException ioex) {
ioex.printStackTrace();
}
i was able to read it if i just write a junit test w/o the jar and w/o the dm-server.
the test is packed into the jar and is at the root of the jar file.
please help!!!!
thanks,
A
You need to use the Class’s
getResourceorgetResourceAsStreammethods to read files from within the jar.This can be done like this:
Note that
getResourceAsStreamreturns null if it can’t find the file.Edit:
Corrected test.xml to /test.xml
Also note that the
Class<T>version ofgetResourceAsStreamdefers to theClassLoader‘sgetResourceAsStreamorgetSystemResourceAsStreamas appropriate.