具有其他项目依赖项的 Eclipse 插件项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2869693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:45:58  来源:igfitidea点击:

Eclipse Plugin project with other project dependencies

javaeclipseeclipse-plugindependencies

提问by James Hu

I have an Eclipse plugin project, and it depends on other projects that I have in my Eclipse workspace. After adding the project dependencies under "Java Build Path" -> "Projects" tab, and also selecting the project in the "Order and Export" I get a java.lang.NoClassDefFoundError.

我有一个 Eclipse 插件项目,它依赖于我在 Eclipse 工作区中的其他项目。在“Java 构建路径”->“项目”选项卡下添加项目依赖项,并在“订单和导出”中选择项目后,我得到一个 java.lang.NoClassDefFoundError。

I'm assuming that the other projects have not been properly included into the plugin. Does anyone know how to fix this?

我假设其他项目没有正确包含在插件中。有谁知道如何解决这一问题?

Thanks, James

谢谢,詹姆斯

回答by Gilbert Le Blanc

An Eclipse plug in project manages dependencies differently than a regular Java project.

Eclipse 插件项目管理依赖项的方式与常规 Java 项目不同。

I'm assuming that you're adding packages with .class files.

我假设您正在添加带有 .class 文件的包。

Define a library folder in your Eclipse plug-in project. Copy any external classes and / or jars to the library folder.

在 Eclipse 插件项目中定义一个库文件夹。将任何外部类和/或 jar 复制到库文件夹。

Open up the MANIFEST.MF file under the META-INF directory. You'll see a formatted editor with 8 tabs on the bottom.

打开 META-INF 目录下的 MANIFEST.MF 文件。您将看到一个带格式的编辑器,底部有 8 个选项卡。

Click on the Runtime tab. Add the external classes and / or jars in the library folder to the Classpath. This will also add these external classes and or jars to the Java Build Path of the project.

单击运行时选项卡。将库文件夹中的外部类和/或 jar 添加到类路径。这也会将这些外部类和/或 jar 添加到项目的 Java 构建路径中。

Click on the Dependencies tab, and add the other Java projects in the Imported Packages dialog. You have to check the box labeled "Show non-exported packages". If your other Java projects are Eclipse plug ins, add them under Required Plug-ins instead.

单击 Dependencies 选项卡,然后在 Imported Packages 对话框中添加其他 Java 项目。您必须选中标有“显示非导出包”的框。如果您的其他 Java 项目是 Eclipse 插件,请将它们添加到所需插件下。

回答by Abdul Rahman K

In case if you're not in a position to copy the dependent project into your plugin project and you are sure about the presence of the dependent project in the target eclipse where plugin is to be installed, then you can either use Runtime.exec()to run the Java class you want to run or ProcessBuilderclass to run the class.

如果您无法将依赖项目复制到您的插件项目中,并且您确定要安装插件的目标 eclipse 中存在依赖项目,那么您可以使用 Runtime.exec()运行 Java您要ProcessBuilder运行的类或类来运行该类。

Like this:

像这样:

// To compile
Process p = Runtime.getRuntime().exec("javac yourclass.java"); 
// To execute
Process p2 = Runtime.getRuntime().exec("java yourclass");

This may be considered in the worst case. I had such an experience and hence thought some may find it useful.

这可以在最坏的情况下考虑。我有这样的经历,因此认为有些人可能会觉得它很有用。