tags:

views:

753

answers:

3

I use ant for creating .jar files in Eclipse. Works great.

I have a .jar file I am working on that expects the code to be in a .jar file (it looks for .properties files in the same directory as the .jar file) -- the standard Eclipse "Run" and "Debug" menus execute the main() method of a specified Java class... but they do it from the directory containing the compiled class files, not a jar file. Is there a way to change this behavior so Eclipse runs code from the appropriate .jar file instead?

(My workaround right now is to run the .jar file externally, with it suspended waiting for a debugger, per Dave Ray's answer to one of my other questions.)

+4  A: 

Yes, you can create a custom "Run Configuration":
a "Java Application" one, with:

  • Classpath tab emptied from its default content (the .class directory) and with the jar added
  • Source tab with its default content (should reference the src directory of the project)

One such configuration can be run or debugged.

alt text

(Example of a custom configuration with jars as user entries)

VonC
A: 

I would try to make the code more robust, make the properties file location configurable, or just make it load it from the classpath. Then you can just directly add the properties file to the eclipse classpath. Problem Sovled!

broschb
A: 

Thanks a lot VonC. I was looking for just the information you have provided. And it worked for me.

shashi
please do not comment by posting a new answer -- instead, add your comment to the bottom of the answer you wish to comment on.
Jason S