【问题标题】:java.lang.NoClassDefFoundError: org/eclipse/draw2d/LightweightSystemjava.lang.NoClassDefFoundError: org/eclipse/draw2d/LightweightSystem
【发布时间】:2013-01-04 06:53:48
【问题描述】:

我正在使用 Eclipse 图形编辑框架 (GEF) 构建一个 Eclipse 插件项目。 可以用我在网上找到的示例代码编写一个单独的类进行测试,代码如下:

public class Test {
    public static void main(String args[]){
        Shell shell = new Shell(); 
        shell.open();
        Display display = shell.getDisplay();
        LightweightSystem lws = new LightweightSystem(shell);
        IFigure panel = new Figure();
        lws.setContents(panel);
        RectangleFigure node1 = new RectangleFigure();
        RectangleFigure node2 = new RectangleFigure();
        node1.setBackgroundColor(ColorConstants.red);
        node1.setBounds(new Rectangle(30, 30, 64, 36));
        node2.setBackgroundColor(ColorConstants.blue);
        node2.setBounds(new Rectangle(300, 300, 64, 36));
        PolylineConnection conn = new PolylineConnection();
        conn.setSourceAnchor(new ChopboxAnchor(node1));
        conn.setTargetAnchor(new ChopboxAnchor(node2));
        conn.setTargetDecoration(new PolygonDecoration());
        Label label = new Label("Midpoint");
        label.setOpaque(true);
        label.setBackgroundColor(ColorConstants.buttonLightest);
        label.setBorder(new LineBorder());
        conn.add(label, new MidpointLocator(conn, 0));
        panel.add(node1);
        panel.add(node2);
        panel.add(conn);
        while (!shell.isDisposed ()) { 
            if (!display.readAndDispatch ()) 
               display.sleep (); 
        }
    }//main
}

有效。

但是 - 当我尝试在 EditorPart (org.eclipse.ui.IEditorPart) 实例类中构建图形时,它变得很糟糕并给了我以下错误代码:

**org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError:** org/eclipse/draw2d/LightweightSystem

很奇怪,因为我在编辑器的createPartControl方法处只写了3行:

Shell shell = parent.getShell();
Display display = shell.getDisplay();
LightweightSystem lws = new LightweightSystem(shell);

所以有没有身体帮助?

【问题讨论】:

    标签: java eclipse eclipse-plugin eclipse-rcp draw2d


    【解决方案1】:

    您的依赖项设置正确吗?您需要为LightweightSystem 添加org.eclipse.draw2d

    【讨论】:

    • Tks,它是由目标平台引起的。进入运行配置>插件>目标平台,添加org.eclipse.draw2d
    猜你喜欢
    • 2013-05-26
    • 2016-04-18
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 2014-06-22
    相关资源
    最近更新 更多