且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eclipse类路径和NoClassDefFoundError

更新时间:2023-01-14 11:32:31

由于您的应用程序是RCP应用程序,因此在编辑代码时使用的eclipse类路径和运行时使用的OSGi类路径之间存在差异。这听起来像您需要将com.myworkplace.child插件添加到com.myworkplace.parent插件的依赖关系列表中。



打开plugin.xml或META -INF / manifest.mf在父项目中。 Eclipse应该打开PDE插件编辑器(基础配置文件的基于表单的编辑器)。单击底部的依赖关系选项卡,并将您的子插件添加到窗体左侧部分的所需插件列表中。或者,您可以将com.myworkplace.child包添加到右侧的Imported Package列表中。两者之间的区别超出了这个答案的范围,但你可以在eclipse文档中阅读,希望你们(希望)正在朝着正确的方向前进。


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 combineacces-s-rules="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.

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.