Reputation: 44978
I have a Java project that I'm working on in Eclipse. I have all my code in a src
. Eclipse automatically compiles my .java files and stores the .class files in a directory called tmp
.
Earlier, I was suing Ant to run my project. My ant script would would compile my Java code, and Jar all the .class files into a .jar and store it into a jar
directory. In this jar
directory I have some other files e.g. settings.cfg
and data.lst
. My application needs these files to run but they should not be included in the Jar. They will be deployed along with my JAR and should reside in the same directory. Currently while developing, I have modified and customised my settings and properties files to contain additional information. I don't want these files replaced every time I have a new build as I would like the data to persist across builds. I'm just looking to get the built JAR into the jar
directory and execute that. The rest of the files stay the same.
How can I configure my Eclipse so that it always compiles my code, JARs it to the jar
directory and executes that JAR. That way, my "extra files" are always in the same place as the JAR.
I'm having a lot of trouble figuring out how to accomplish this.
Upvotes: 1
Views: 196
Reputation: 44978
The answer was found on another SO post. It was about creating a new "Run Configuration", removing the default classpath entries and adding a the folder containing the JAR i.e. the jar
directory and also the JAR file itself.
Here: https://stackoverflow.com/a/1732316/304151
I also had to modify the build configuration a bit. For automatic builds, it used the Java Builder to compile all the .java files into .class files and store it in the tmp
directory. I used a custom Ant task to package all the .class files from the tmp
directory into a JAR and store it in the jar
directory. This is the file that Eclipse executes.
Upvotes: 0
Reputation: 21
If you need this feature for fast running/debuging, create new Run Configuration and in the Arguments tab, Working Directory specify the "jar" directory.
Upvotes: 2
Reputation: 1510
In your project, right click Properties, in "Java build path" menu you can set "default output directory" in the Source tab and make it point to jar directory:
Upvotes: -1