Resources access problem from JAR

Posted by aeter on Stack Overflow See other posts from Stack Overflow or by aeter
Published on 2010-03-16T14:46:57Z Indexed on 2010/03/16 15:01 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

I have the following directory structure of a project:

Folder "project" in Eclipse:
--folder "src"
--folder "resources"
----trayicon2.png
--folder "db" 
----test.db
--folder "bin" 

I'm accessing the image with:

Image image = Toolkit.getDefaultToolkit().getImage("resources/trayicon2.png");

and from Eclipse that is not a problem. Then I generate an "executable jar file", and add the dirs, making a directory structure of:

Folder "project"
--folder "db"
----test.db
--folder "resources"
----trayicon2.png
--project.jar 

And now the image is no more accessible. Also, the database is no more accessible; while in Eclipse I used to access it with:

Connection conn = DriverManager.getConnection("jdbc:sqlite:db/test.db");

How can I access the resources (images and db) after generating the jar file "project.jar"?

© Stack Overflow or respective owner

Related posts about java

Related posts about jar