This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have the following structure of the ear:
Inside the lib, I have all the relevant jar files needed for the application. Now in the lib folder, I have 2 jar files (a.jar and b.jar) each containing a property file of the same name.
I need to read the contents of the file in b.jar.
TestImpl.class.getClassLoader().getResourceAsStream(filename), where filename is the name of the property file.
TestImpl.class exists in a.jar.
Whenever I execute this, the property file in a.jar is read instead of the one in b.jar.
The same works fine in another ear structure as under:
----all relevant wars and jar files
Here a.jar and d.jar inside the ear contain the property file of the same name.
When TestImpl.class.getClassLoader().getResourceAsStream(filename), where TestImpl.class is part of a.jar is executed, then the property file in d.jar is read.
I am not sure how it works in the second case? The filename does not contain the /, therefore it goes to the root of the jar file and picks up the property file.
But how does it gives preference to the jar file. I think it is based on the classpath but then i have no control over how the jar files are loaded at runtime by the application server.
How do I solve this problem withoput writing new code and using the same piece of code in both scenarios and have the correct result.
Deepti Vashisht wrote:I think it is based on the classpath but then i have no control over how the jar files are loaded at runtime by the application server.
Yes, that's a pretty good summary of how it works. Although because Websphere uses a lot of different classloaders, it's a bit more complicated than just "the classpath".
Anyway my suggestion would be to fix your deployment so that you aren't deploying two copies of the resource. Or at least if you must deploy two copies, make sure they contain the same data, so that it doesn't matter which one Websphere chooses.
Joined: Jun 15, 2009
I resolved the issue by making sure that the property file names in the 2 jar files were different.
Joined: Jun 15, 2009
I was able to resolve the issue by having different property file names in the 2 jar files.