views:

39

answers:

3

Hi,

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 corresponding 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
A: 

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.

Manuel Selva
Hi Manuel, I've added the library (you can only add directories) in the classpath field on the runtime tab (step 3 in my original post) which creates an entry bundle-classpath in the file. I've had a look on the build tab and added the library but that doesn't change anything at all.
mfrey
What is the class eclipse complains with NoclassDefFoundError ? Do you launch your code as Eclipse application or java application ? You don't have to do step 2 of your question because you write a plugin.
Manuel Selva
I'm launching the code as eclipse application. The class it is complaining is OWLOntologyManager which is part of the OWL-API library. There is a initializiation in the doSave and doLoad method in the first line of both methods. I've built a test project where I'm using the library and everything works fine (so, it's not a problem with the library itself). I've also tried (as a test) to use another class from the library which causes the same exception.
mfrey
A: 

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.

Zoltán Ujhelyi
The exception is thrown while I'm accessing the library.
mfrey
+1  A: 

Hi,

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

mfrey