2013-05-31 43 views
1

我想用我的插件开发draw2d。现在,我只有在我的代码是:java.lang.NoClassDefFoundError:org/eclipse/draw2d/LightweightSystem尽管它被添加

import org.eclipse.draw2d.LightweightSystem; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.widgets.Canvas; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.ui.part.*; 


public class GraphView extends ViewPart { 

public GraphView() { 

} 
@Override 
public void createPartControl(Composite parent) { 

    //use LightweightSystem to create the bridge between SWT and draw2D 
    final LightweightSystem lws = new LightweightSystem(new Canvas(parent, SWT.NONE)); 

} 

@Override 
public void setFocus() { 
    // TODO Auto-generated method stub 

} 
} 

我得到org.eclipse.e4.core.di.InjectionException:java.lang.NoClassDefFoundError:组织/日蚀/ Draw2D的/ LightweightSystem当我启动我的eclipse应用程序。我把org.eclipse.draw2d作为外部jar添加到我的项目中。

有人可以帮助我吗?提前致谢!

回答

4

将jar添加到构建路径只会让IDE中的编译器找到类。对于RCP应用程序,您必须将该罐作为外部罐添加到您的plug-in.xml中。然后,jar会被捆绑到您的应用程序中,并在运行时可用。

您可以在选项卡Runtime的Eclipse编辑器中执行此操作。在classpath部分点击Add...,然后在这里添加你的jar。这会自动将jar添加到您的构建路径,以便您可以在此之前将其更好地移除。

你可以找到详细的描述(图片)在这里:Adding a jar file to your Eclipse RCP Plugin

+0

谢谢˚F或给我一个提示。其实,这里是我找到的解决方案: 当我收到错误时,Manifest.mf中的“必需包”文件看起来像这样: **需要包:org.eclipse.ui, org.eclipse.core。运行时** 我将它改为:** Require-Bundle:org.eclipse.core.runtime, org.eclipse.ui, org.eclipse.draw2d, org.csstudio.swt.widgets; bundle-version =“2.0.1”; resolution:=可选, org.csstudio.swt.xygraph; bundle-version =“2.0.1”; resolution:=可选** 修正了它! 谢谢 – user2033666

0

现在把这个作为回答我的问题:

在MANIFEST.MF在我的“捆绑要求”文件看起来像这样,当我得到了错误:

Require-Bundle: org.eclipse.ui, 
       org.eclipse.core.runtime 

我把它改为:

Require-Bundle: org.eclipse.core.runtime, 
       org.eclipse.ui, 
       org.eclipse.draw2d, 
       org.csstudio.swt.widgets; 
bundle-version="2.0.1";resolution:=optional, org.csstudio.swt.xygraph; 
bundle-version="2.0.1";resolution:=optional** 
相关问题