Beier
Beier

Reputation: 3157

Question about Java Eclipse Export function

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

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

Upvotes: 2

Views: 1494

Answers (2)

James E. Ervin
James E. Ervin

Reputation: 161

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.

Upvotes: 0

Licky Lindsay
Licky Lindsay

Reputation: 1056

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.

Upvotes: 3

Related Questions