tags:

views:

181

answers:

2

I'm going to try to give as much detail as possible here, pardon me if some is irrelevant. I have two projects in eclipse. Project 1: com.myworkplace.parent, with code in the package of the same name. Project 2: com.myworkplace.child, with code in package of the same name (I moved my code to that package, from the default package, if that makes a difference). Both are located in my workspace folder and structured the way you'd expect them to be, as far as I can tell.

I've added child to the build path of parent in eclipse using Java Build Path -> Projects -> Add. Parent's .classpath file contains the entry:

    <classpathentry combineaccessrules="false" kind="src" path="/com.myworkplace.child"/>

I add a reference to a com.myworkplace.child.Child class in parent, import it, compile it with no errors, run and get:

java.lang.NoClassDefFoundError: com/myworkplace/child/Child

What gives?

Edit: The parent application is an RCP app, maybe OSGI (I really don't know much about RCP and related stuff.) Some googling leads me to believe it might have something to do with this.

A: 

If your code is running in an application server, you need to configure the Classpath correctly for that application server.

To do that, find your Servers tab, double-click it, click Open Launch Configuration in the new tab that appears in the main editing area, click the Classpath tab and ensure the Classpath there is correct.

Eric J.
nope it's not running on application server
jsn
+1  A: 

Since your application is an RCP app there is a difference between the eclipse classpath that is used while you are editing code and the OSGi classpath that is used at runtime. It sounds like you need to add the com.myworkplace.child plugin to the list of dependencies of the com.myworkplace.parent plugin.

Open either plugin.xml or META-INF/manifest.mf in the parent project. Eclipse should open the PDE plugin editor (a form based editor for the underlying config files). Click the Dependencies tab at the bottom and add your child plugin to the "Required Plug-ins" list on the left hand section of the form. Alternately you could add the com.myworkplace.child package to the "Imported Package" list on the right. The difference between the two is beyond the scope of this answer, but you can read about that in the eclipse docs now that you (hopefully) are moving in the right direction.

ChrisH
This is correct. If it doesn't work after this, right click on the project in the navigator, and select the 'Update Classpath' option.
Chris Dennett
Right, parent is an RCP plugin. Child is not and has nothing to do with RCP. So I can't add it via required plugins.Mysteriously, it is also missing from the list of packages that can be imported. I did manage to run the app with no errors by one method: export child as a jar and add it under the runtime tab of plugin properties. Ugly. Anyway, this is a good enough answer to be accepted.
jsn
@jsn Just a friendly recommendation of something to consider without knowing the specifics of your situation: You should consider converting the child project to a plugin. The only difference is the addition of a META-INF/manifest.mf file (or the addition of a few OSGi specific entries to that file if you already have one). The child project would still be completely usable as a standalone (non-OSGi) jar file for other purposes, and it will make for a more elegant integration with the parent RCP app.
ChrisH
Thanks for the suggestion, I'll check it out.
jsn