简体   繁体   English

Eclipse RCP:java.lang.ClassNotFoundException一个运行时

[英]Eclipse RCP: java.lang.ClassNotFoundException a runtime

One of my plugins uses a library (jar file). 我的一个插件使用了一个库(jar文件)。

  1. I created a folder called lib in my plugin and placed the jar file into it. 我在我的插件中创建了一个名为lib的文件夹,并将jar文件放入其中。
  2. I configured the build path by adding the jar file with "Add JARS..". 我通过添加带有“Add JARS ..”的jar文件来配置构建路径。
  3. I use the classes of the jar file in the plugin and it compiles fine. 我在插件中使用jar文件的类,它编译得很好。
  4. I start the RCP and get a ClassNotFoundException about the classes in the jar file. 我启动RCP并获取有关jar文件中的类的ClassNotFoundException。

What am I missing? 我错过了什么?

Welcome to the wonderful world of OSGi! 欢迎来到OSGi的精彩世界! :D :d

You have two options: 您有两种选择:

Repack the JAR as an OSGi bundle 将JAR重新打包为OSGi包

You can go the OSGi way and repack your JAR in an OSGi bundle. 您可以使用OSGi方式并在OSGi包中重新打包JAR。 This is clean and recommended in the sense of OSGi, since all code should be packaged in OSGi bundles (which in you case are called Eclipse plugins ). 从OSGi的意义上讲,这是干净的并且是推荐的,因为所有代码都应该打包在OSGi包中(在你的例子中称为Eclipse插件 )。 However, this means additional work and I personally do not like it. 但是,这意味着额外的工作,我个人不喜欢它。

Use the bundle class path 使用bundle类路径

Put the JAR file to the root (or a folder called lib ) of your bundle and add a Bundle-ClassPath entry to your manifest: 将JAR文件放到捆绑包的根目录(或名为lib的文件夹)中,并向清单中添加Bundle-ClassPath条目:

Bundle-ClassPath: .,lib/library.jar

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

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