Question about Java Eclipse export feature

I am trying to run the Eclipse Java "Export Runnable JAR" JAR file. It creates a single JAR with all the files in it, which is great. But one problem, in my project I have two directories and several external libraries, for example the following layout

  • src
  • resources
    • mypic.jpg
  • JRE system library
  • Linked Libraries
    • a bunch of external libraries

As usual, 'src' contains all my codes. and the resources contain some image files that I am using in the code. in my code, when I link to mypic.jpg, I do:

String filename = "resources / mypic.jpg";

However, when I export the project as an executable JAR file, it completely ignores the resource directory, it puts mypic.jpg in the top level directory, which makes "resources / mypic.jpg" in my code won't work at all. The resource directory is not created in either the JAR file

I tried to create a "resources" directory using either "New-> Folder", "New-> Source Folder", none.

here are my "Source folders on build path" in the "Build path" config

MyProject / resources MyProject / src

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

+2


source to share


2 answers


I would recommend using the approach described here using maven:

How to create an executable JAR with dependencies using Maven?



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

+3


source


What Eclipse is doing right. You can specify that the source and output directories point to the project root and then move all java source files from the src / directory and into your project root, which would make this work.



However, I would either live by having access to mypic.jpg from the root of the classpath, or put it in your project under resources / resources.

0


source







All Articles