This discussion is archived
4 Replies Latest reply: Apr 15, 2010 7:57 PM by 843804 RSS

Loading resource from inside jar file?

843804 Newbie
Currently Being Moderated
Hi all, I am writing a library which is to be packaged as a .jar file. I have resources (text files) inside this jar file. I want classes inside the jar file to be able to load them. I have no problems when I run the jar as a standalone, but when I use this jar as part of another application (specifically I am putting it inside an Eclipse plugin), it does not look for the resource files inside the jar. Instead it tries to look for the resource files inside the Eclipse execution root when I am on Windows and some unknown place when on Linux.

I have tried:
ClassLoader.getSystemResource("res1.txt").getPath()
and
Main.class.getResource("res1.txt").getPath() + "\n");
and
Main.class.getClassLoader().getResource("res1.txt");
where 'Main' is the name of my class inside the jar file.

All three work when doing standalone but not when packaged.