2

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

Beier
  • 3,127
  • 10
  • 28
  • 24
  • For what it's worth, a simple export-to-jar (as opposed to export-to-runnable-jar) does include the resources directory. – CPerkins Aug 18 '09 at 20:03
  • hm, why export as runnable doesn't do that? I mean, isn't it this common sense to preserve dir structure? or probably I'm missing something? – Beier Aug 18 '09 at 23:28

2 Answers2

3

I would recommend taking the approach described here using maven:

How can I create an executable JAR with dependencies using Maven?

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.

Community
  • 1
  • 1
Licky Lindsay
  • 1,048
  • 6
  • 10
0

What Eclipse is doing is correct. You could make the source and output directories point to the root of the project and then move all of our java source files out of the src/ directory and into your project root, that would make this work.

I would however either live with being able to access the mypic.jpg from the root of the classpath or put it in your project under resources/resources.

James E. Ervin
  • 161
  • 1
  • 3