开发者

NoClassDefFoundError exception while using external library in EMF plugin project

开发者 https://www.devze.com 2023-01-16 01:23 出处:网络
I\'m working on a EMF project where I\'ve created a ecore model from a mdl file. I created the corresponding gencore file and generated the code from the gencore file. While EMF has a own serializatio

I'm working on a EMF project where I've created a ecore model from a mdl file. I created the corresponding gencore file and generated the code from the gencore file. While EMF has a own serialization mechanism based on XMI I want to support my project with a own serializiation mechanism.

So far, I've done the necessary steps and if I use the debugger the correspond开发者_JAVA技巧ing methods are called. In order to read and write a file representation of my model I want to use an external library. I've done the following steps

  1. Created a directory lib/ in my plugin project where I've put the external library
  2. Added the library to the build path of the project
  3. Added the directory to the bundle-classpath (Manifest.mf)
  4. Added the directory to the bin.includes of the build.properties

If I try to run my code I get a NoClassDefFoundError exception and I don't know why. I've created a run configuration where I'm starting the project as a eclipse application. So somebody has an idea what I'm missing?

Thanks in advance!

Michael

Edit: Below my Manifest.mf file

Manifest-Version: 1.0  
Bundle-ManifestVersion: 2  
Bundle-Name: de.hs_rm.cs.vs.dsm.OWL  
Bundle-SymbolicName: de.hs_rm.cs.vs.dsm.owl;singleton:=true
Bundle-Version: 1.0.0  
Bundle-ClassPath: lib/,
 .
Bundle-Localization: plugin  
Bundle-RequiredExecutionEnvironment: JavaSE-1.6  
Export-Package: owl,  
 owl.impl,  
 owl.util,  
 rdfs,  
 rdfs.impl,  
 rdfs.util  
Require-Bundle: org.eclipse.core.runtime,  
 org.eclipse.emf.ecore;visibility:=reexport  
Bundle-ActivationPolicy: lazy  

and also my build.properties

bin.includes = .,\
               model/,\
               META-INF/,\
               plugin.xml,\
               plugin.properties,\
               lib/
jars.compile.order = lib/,\
                     .
source.. = src/
output.. = bin/
source.lib/ = lib/
jars.extra.classpath = lib/owlapi-bin.jar


it's not really a hundred percent solution since I'm not aware what exactly the problem was at all. I've found a link where somebody had the exactly same problem (added a jar as library, NoClassDefFoundError exception during execution). So far, the necessary steps are:

  1. Import JARs using the "Import -> File System"
  2. Add the JAR-file(s) to the classpath section of the Manifest/plugin.xml runtime tab
  3. Press "New..." to add "." library back to the classpath
  4. Check that the binary build exports the new JAR-file(s) on the Build tab
  5. Press save
  6. Select the coressponding project in the project explorer view, right click and select "PDE Tools -> Update classpath". This will add the newly added JAR-file(s) to the project's classpath.

I've had some trouble with the last step since I've added the library by myself to the build path of the project. Every time I did this eclipse removed the library from the build path while executing the "Update classpath command". I've repeated step six without adding the library to the build path by myself and it's now working.

It seems a bit odd to me, but it's now working. Anyway I would like to thank you for your help!

Regards, Michael


If you are writing Eclipse plugins and not plain old Java project you must add your library in the classpath field of the Runtime tab of the Manifest.mf editor.


Do you get the NoClassDefFoundError when trying to access the lib or when trying to access the Ecore model? If it is the latter case, check, whether your emf package has been registered in the plugin.xml file. Look for something like the following part:

<extension point="org.eclipse.emf.ecore.generated_package">
  <package
       uri="«package URI here»"
       class="«package class name here»"
       genModel="«genmodel location here»"/>
</extension>

This part can be missing, if the plugin.xml was generated before the genmodel was used for generation, as neither the manifest, nor the plugin.xml gets updated during the code generation process.

On the other hand, if the library accessing throws the exception, then I would try to remove and re-add the dependency, or clean build a project, but these seem unlikely to solve the exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消