Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse debug-time classpath problem: How do you include a dependent project's output into a web project's runtime classpath?

So I started with a web services project (just a dynamic web project) that builds and debugs correctly from eclipse. We've pulled a chunk of common code out that we want to put into a shared library so now those classes are going into a separate jar project that the web project references.

On the web project, I did Project->Properties->Java Build Path->Projects->Add and added the jar project. And this correctly solved all the compile-time classpath problems and everything builds fine. But at runtime, when the tomcat server fires up, spring attempts to inject some of the classes contained in the jar file and I get a NoClassDefFoundError.

My .class and properties files and the contents of my META-INF directory are showing up in the ./build directory, but my WEB-INF/lib directory seems to be referenced in-place, and the jar dependency doesn't get copied in to it to show up as part of the Web App Library.

What is the magical incantation to tell eclipse that the other jar project needs to be available to tomcat at runtime? From our ant build script, we first just build the other project into WEB-INF/lib and everything works fine, but not for eclipse debugging.

like image 510
Brian Deacon Avatar asked Nov 28 '08 21:11

Brian Deacon


People also ask

How do I add resources folder properties at runtime into Eclipse classpath?

Right Click on the project-name in Package Explorer, select Properties, select Java Build Path on the left, select Source tab on the right, click on Add Folder, browse through the project's directories to select the resources folder or whatever you need to add to the eclipse classpath, hit OK, again hit OK. Done.

How do you debug and run in Eclipse?

Starting the Debugger. To debug your application, select a Java file with a main method. Right-click on it and select Debug As Java Application. If you started an application once via the context menu, you can use the created launch configuration again via the Debug button in the Eclipse toolbar.

How do I place a debug point in Eclipse?

To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position. The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.


2 Answers

I figured this out after spending some time on it. If you are in Eclipse Helios , go to properties > deployment assembly > add > project and select the dependent project you wish to add.

like image 183
Anoop Isaac Avatar answered Dec 01 '22 22:12

Anoop Isaac


Java EE module dependencies would solve this problem. You have already done the task of extracting your common classes into its own project, possibly because other projects depend on these classes. Either way, you'll have to ensure that this is a Utility project (appears under Java EE in the project wizards), and not just a plain Java project. One that is done, you can proceed to add the Utility project to your build path (compile-time path) as you have figured out.

The additional (final) step is to establish a Java EE module dependency between your Dynamic Web project and the shared library, which causes the utility's classes to be placed in WEB-INF\lib during deployment, and even during export of the WAR. To do so, visit the dynamic web project's properties, and browse to the Java EE module dependencies. Ensure that your utility project is selected here. Redeploy/publish your application and you should be good to go.

like image 27
Vineet Reynolds Avatar answered Dec 01 '22 20:12

Vineet Reynolds