views:

30

answers:

2

As a Java/Eclipse noob coming from a Visual Studio .NET background, I'm trying to understand how to set up my run/debug environment in the Eclipse IDE so I can start stepping through code.

I have built my application with separate src and bin hierarchies for each library project, and each project has its own jar. For example, in a Windows environment, I have something like:

c:\myapp\myapp_main\src\com\mycorp\myapp\main

...and a parallel "bin" tree like this:

c:\myapp\myapp_main\bin\com\mycorp\myapp\main

Other supporting projects are, similarly:

c:\myapp\myapp_util\src\com\mycorp\myapp\util

(and a parallel "bin" tree), etc.

So, I end up with, e.g., myapp_util.jar in the ...\myapp_util\bin... path and then add that as an external archive to my myapp_main project.

I also use utilities like gluegen-rt.jar, which I add ad external dependencies to the projects requiring them.

I have been able to run outside of the Eclipse environment, by copying all my project jars, gluegen-rt DLL, etc., into a "lib" subfolder of some directory and executing something like:

java -Djava.library.path=lib -DfullScreen=false -cp lib/gluegen-rt.jar;lib/myapp_main.jar;lib/myapp_util.jar; com.mycorp.myapp.Main

In the IDE, however, When I first pressed F11 to debug I got a message about something like /com/sun/../glugen... not being found by the class loader.

So, to debug, or even just run, in Ecplipse, I tried setting up my VM arguments in the Galileo Debug -> (Run/Debug) Configurations to be the command line above, beginning at "-Djava.libary.path...". I've put a lib subdirectory - just like the above with all jars and the native gluegen DLL - in various places, such as beneath the folder that my main jar is built in and as a subfolder of my Ecplipse starting workspace folder, but now the debugger can't find the main class:

java.lang.NoClassDefFoundError: com.mycorp.myapp.Main

Although the Classpath says that it is using the "default classpath", whatever that is. Bottom line, how do I assemble the constituent files of a multi-project application so that I can run or debug in Eclipse?

+1  A: 

if you want project A to have project B (and its libs) on its classpath, then goto project A's properties, select Java Build Path, then select the Projects tab. Here you Add project B.

Although you may be generating jars for each project, eclipse doesn't pay much attention to the jars. If you are going to have lots of java projects with lots of 3rd party dependencies, you may want to look at something like m2eclipse.

Ron
I checked the Classpath tab for the Run and Debug configurations, and they both have paths to all the jars listed under "User entries", though not "Bootstrap entries". Is that what you mean?
Buggieboy
yes exactly. the sources of truth will be the .classpath and .project files in each eclipse java project. You can edit them by hand to remove some of the magic, but those configs are what you manipulate from the project properties modal window. As you change your projects' dependencies, your run/debug launch configs should transparently reflect any changes.
Ron
+1  A: 

The recommended way of doing things is to configure the build path. This is a nice article describing the process.

kgiannakakis
Great article. Thanks!
Buggieboy