Cristiano Coelho
Cristiano Coelho

Reputation: 1735

Make a jar library with working resource files

I have made some kind of library, and it needs some xml files so i have stored them in a resource folder and i load it like it like this:

MyClass.class.getClassLoader().getResourceAsStream("resources/somefile.xml");

Everything works fine when running from the same jar. However, if i decide to export this code as a .jar and import it as an external jar from another program, the above code fails to get the resource. How can i do this correctly?

Note: Actually the jar file is an android library jar (android project marked as library in eclipse), it seems to work fine in my android app, but since it is just a library i want to test it out in a non android app, everything works fine except for getting the resource file. Should i write the library as a simple java project?

Upvotes: 3

Views: 910

Answers (1)

Cristiano Coelho
Cristiano Coelho

Reputation: 1735

Shame on me, the resources files needed to be added to the src folder or any other folder set in the class path.

Upvotes: 2

Related Questions