Eclipse 插件:java.lang.NoClassDefFoundError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18105361/
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-08-11 22:26:05  来源:igfitidea点击:

Eclipse plugin: java.lang.NoClassDefFoundError

javaeclipseexceptioneclipse-plugin

提问by displayname

As you can see:

如你看到的:

enter image description here

在此处输入图片说明

I added jni4net.j-0.8.6.0.jarto my referenced libraries but I stell receive a java.lang.NoClassDefFoundErrorException:

我添加jni4net.j-0.8.6.0.jar到我引用的库,但我 stell 收到一个java.lang.NoClassDefFoundError异常:

java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge
    at sibeclipseplugin.debug.DebuggerInterface.initialize(DebuggerInterface.java:15)
    at sibeclipseplugin.debug.SibDebugTarget.<init>(SibDebugTarget.java:65)
    at sibeclipseplugin.ui.launch.LaunchConfigurationDelegate.launch(LaunchConfigurationDelegate.java:30)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:858)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1018)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.run(DebugUIPlugin.java:1222)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.ClassNotFoundException: net.sf.jni4net.Bridge cannot be found by SIBEclipsePlugin_0.0.0.1
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 8 more

I have no idea what the problem is. When I start the project as Eclipse-Application it can't find that class. Running the same code in a normal Java-Project works.

我不知道问题是什么。当我以 Eclipse-Application 的身份启动项目时,它找不到那个类。在正常的 Java 项目中运行相同的代码。

Does anybody know how to fix this?

有谁知道如何解决这个问题?

采纳答案by Tassos Bassoukos

You need to add the jar files in your build.properties bin.includes entry. Also, in your MANIFEST.MF file, they need to be added in the Runtime->Classpath list (corresponds to the Bundle-ClassPath entry in the MANIFEST.MF).

您需要在 build.properties bin.includes 条目中添加 jar 文件。此外,在您的 MANIFEST.MF 文件中,它们需要添加到 Runtime->Classpath 列表中(对应于 MANIFEST.MF 中的 Bundle-ClassPath 条目)。

Edit: if you just put them in the referenced libraries, the OSGi system will not be aware of that fact.

编辑:如果您只是将它们放在引用的库中,OSGi 系统将不会意识到这一事实。

回答by Abhishek Singh

This may also happen if your jar file is dependent on some other jar files for their woking and you have not added them in your project.

如果您的 jar 文件依赖于其他一些 jar 文件,并且您没有将它们添加到您的项目中,则也可能发生这种情况。

回答by Steve B

I had exactly the same issue with my .jar in my Referenced Libraries folder (jar was added via right click project --> Build Path --> Configure Build Path --> Libraries --> Add External Jar).

我的引用库文件夹中的 .jar 有完全相同的问题(jar 是通过右键单击项目添加的 --> 构建路径 --> 配置构建路径 --> 库 --> 添加外部 Jar)。

This fixed it: right click project --> Build Path --> Configure Build Path --> Order and Export. Make sure your .jar file is checked.This adds it to the build class path. You'd think this would be automatically checked after first adding the .jar via the above method but it wasn't.

这修复了它:右键单击项目--> 构建路径--> 配置构建路径--> 订购和导出。确保您的 .jar 文件被选中。这会将其添加到构建类路径中。您会认为这会在通过上述方法首次添加 .jar 后自动检查,但事实并非如此。

回答by AHA

It is not marked to export in the project properties: "Project Properties" > "Order and Export" tab > make sure the .jar file is checked for export.

它没有在项目属性中标记为导出:“项目属性”>“订购和导出”选项卡 > 确保检查 .jar 文件以进行导出。