views:

309

answers:

1

I'm trying out the Eclipse Java 'Export Runnable JAR file". It creates a single JAR with all files in it, which is great. But one issue, in my project I have two directories and a few external libraries, like the following layout

  • src
  • resources
    • mypic.jpg
  • JRE System Library
  • Referenced Libraries
    • a bunch of external libraries

As usual 'src' contains all my codes. and resources contains some image files I use in the code. in my code, when I refer to mypic.jpg, I do:

String filename = "resources/mypic.jpg";

However, when I Export the project as runnable JAR file, it totally ignores the 'resources' directory, it put mypic.jpg into the top level directory, which makes "resources/mypic.jpg" in my code won't work at all. 'resources' directory is not created neither in the JAR file

I tried creating the "resources" directory using both 'New->Folder', 'New->Source Folder', none avail.

here is my "Source folders on build path" on Build Path configuration

MyProject/resources MyProject/src

My Eclipse build (Windows XP): Eclipse Java EE IDE for Web Developers. Build id: 20090621-0832

+2  A: 

I would recommend taking the approach described here using maven:

http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven/574650

Yes it will require "mavenizing" your project and learning how to use Maven but sooner or later you are going to want to build your project outside of Eclipse.

Licky Lindsay