简体   繁体   English

Eclipse插件开发:插件A在插件B中使用类,导出为jar并安装到eclipse后,发生NoClassDefFoundError

[英]Eclipse Plug-ins develop: Plug-in A use a Class in Plug-in B, after exporting as jars and installed in to eclipse, NoClassDefFoundError occurs

Plugin A uses a class,ClassB, which is from Plugin B.When "run as eclipse application", everything goes well; 插件A使用了一个类B,它来自于插件B。当“以Eclipse应用程序运行”时,一切运行良好; however, when PluginA adn Plugin B are exported as Jar, and install into a new eclipse platform, they run well independently, but crash when the codes reach the line where Plugin A uses the ClassB. 但是,当PluginA和Plugin B导出为Jar并安装到新的Eclipse平台时,它们可以独立运行,但是当代码到达插件A使用ClassB的行时会崩溃。

error log: ava.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException 错误日志:ava.lang.NoClassDefFoundError原因:java.lang.ClassNotFoundException

In plugin org.jboss.vpe.browsersim.eclipse, there is BrowserSimLauncher.java in the package org.jboss.vep.browsersim.eclipse.launcher; 在插件org.jboss.vpe.browsersim.eclipse中,包org.jboss.vep.browsersim.eclipse.launcher中有BrowserSimLauncher.java;

In plugin org.ayound.js.debug.core, there exits a java file "JsLaunchConfigurationDelegate.java", and I put BrowserSimLauncher.launchBrowserSim(startUrl); 在插件org.ayound.js.debug.core中,退出一个Java文件“ JsLaunchConfigurationDelegate.java”,然后将BrowserSimLauncher.launchBrowserSim(startUrl)放进去;

into it, this means I've used previous plugin's class 'BrowserSimLauncher' in the latter plugin. 在其中,这意味着我在后一个插件中使用了前一个插件的类“ BrowserSimLauncher”。

I also do all the"dependencies things", including adding lines to latter plugin's manifest.mf: 我还完成所有“依赖项”,包括在后一个插件的manifest.mf中添加行:

Import-Package: org.jboss.tools.vpe.browsersim.eclipse.launcher

and to previous plugin's manifest.mf: 和以前的插件的manifest.mf:

Export-Package: org.jboss.tools.vpe.browsersim.eclipse.launcher

In the development environment, both plugins compiles successfully, when "run as eclipse application", things goes well, and the latter plugin can sucessfully call BrowserSimLauncher.launchBrowserSim(startUrl); 在开发环境中,两个插件都可以成功编译,当“以Eclipse应用程序运行”时,一切顺利,后一个插件可以成功调用BrowserSimLauncher.launchBrowserSim(startUrl); ; ;
however, when I exported both plugins as several .jar files, and copy them into the /plugin folder of another eclipse directory, start the eclipse, both plugins can run well independently, but the plugin fails to call BrowserSimLauncher.launchBrowserSim(startUrl); 但是,当我将两个插件导出为几个.jar文件,并将它们复制到另一个eclipse目录的/ plugin文件夹中,启动eclipse时,两个插件可以独立运行,但是插件无法调用BrowserSimLauncher.launchBrowserSim(startUrl); . and the error log show as follow: 错误日志显示如下:

    !ENTRY org.eclipse.core.jobs 4 2 2015-01-06 16:29:03.817
!MESSAGE An internal error occurred during: "Launching index.html".
!STACK 0
java.lang.NoClassDefFoundError: org/jboss/tools/vpe/browsersim/eclipse/launcher/BrowserSimLauncher
    at org.ayound.js.debug.launch.JsLaunchConfigurationDelegate.launch(JsLaunchConfigurationDelegate.java:101)
    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$8.run(DebugUIPlugin.java:1222)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.ClassNotFoundException: org.jboss.tools.vpe.browsersim.eclipse.launcher.BrowserSimLauncher cannot be found by org.ayound.js.debug.core_2.2.0
    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(ClassLoader.java:358)
    ... 6 more

the latter plugin(js.debug.core) can't find the previous plugin(browsersim.eclipse)! 后一个插件(js.debug.core)找不到前一个插件(browsersim.eclipse)!

If you just copy plugins in to the Eclipse 'plugins' directory then you need to specify the '-clean' option when you start Eclipse to get it to rebuild the plugin dependencies cache. 如果仅将插件复制到Eclipse的“ plugins”目录中,则在启动Eclipse时需要指定“ -clean”选项以使其重建插件依赖项缓存。

You can specify '-clean' on the Eclipse command line or in the eclipse.ini file (here it must be before any -vmargs line). 您可以在Eclipse命令行或eclipse.ini文件中指定“ -clean”(此处必须在任何-vmargs行之前)。

It is safe to always specify -clean but it will slow down the Eclipse start a bit. 始终指定-clean是安全的,但是会稍微减慢Eclipse的启动速度。

supplements: 补品:

Just startup eclipse with option "-clean", problem solved. 只需使用“ -clean”选项启动Eclipse,问题就解决了。 Details are from reference article : 详细信息来自参考文章

What it does: 它能做什么:

if set to "true", any cached data used by the OSGi framework and eclipse runtime will be wiped clean. 如果设置为“ true”,则将清除OSGi框架和Eclipse运行时使用的所有缓存数据。 This will clean the caches used to store bundle dependency resolution and eclipse extension registry data. 这将清除用于存储捆绑包依赖关系解析和Eclipse扩展注册表数据的缓存。 Using this option will force eclipse to reinitialize these caches. 使用此选项将强制eclipse重新初始化这些缓存。

How to use it: 如何使用它:

  • Edit the eclipse.ini file located in your Eclipse install directory and insert -clean as the first line. 编辑位于Eclipse安装目录中的eclipse.ini文件,并在第一行插入-clean
  • Or edit the shortcut you use to start Eclipse and add -clean as the first argument. 或编辑用于启动Eclipse的快捷方式,并添加-clean作为第一个参数。
  • Or create a batch or shell script that calls the Eclipse executable with the -clean argument. 或创建一个批处理或Shell脚本,该脚本使用-clean参数调用Eclipse可执行文件。 The advantage to this step is you can keep the script around and use it each time you want to clean out the workspace. 此步骤的优点是,您可以保留脚本,并在每次要清理工作区时都使用它。 You can name it something like eclipse-clean.bat (or eclipse-clean.sh ). 你可以将其命名类似eclipse-clean.bat (或eclipse-clean.sh )。

(From: http://www.eclipsezone.com/eclipse/forums/t61566.html ) (摘自: http : //www.eclipsezone.com/eclipse/forums/t61566.html

Other eclipse command line options: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html 其他eclipse命令行选项: http : //help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM