5

I am trying to use Maven for managing the dependencies of my plug-in project. The dependencies are correctly stated in the POM.xml. Even though, I get the exception :

java.lang.NoClassDefFoundError

Is it the correct way for solving dependencies for an Eclipse plug-in project?

Sou
  • 351
  • 2
  • 11
  • Which class is stated? Can you post significative stack trace and pom.xml? Meanwhile, take a look at this [Why am I getting a NoClassDefFoundError in Java?](https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – WoAiNii May 27 '20 at 18:26
  • I am using Swagger-Parser, when I run my code from a main as a Java Application, it runs fine. But when I run it as a plug-in it doesn't. The class which is not found is java.lang.NoClassDefFoundError: io/swagger/v3/parser/OpenAPIV3Parser – Sou May 27 '20 at 18:45
  • Can you post how do you run it as a plugin, maven goal? – WoAiNii May 27 '20 at 18:56

1 Answers1

1

Eclipse plug-ins must use the Require-Bundle or Import-Package statements in the plug-in's MANIFEST.MF to specify their dependencies.

Plug-ins can only be dependent on other plug-ins.

If you want to use a jar which is not a plug-in it must be included in the plug-in and included in the Bundle-Classpath in the MANIFEST.MF. You will also have to update the build.properties file to include the jars in the plug-in build.

Example MANIFEST.MF extract that includes 3 jars in the plug-in:

Require-Bundle: greg.music.core;bundle-version="1.0.0",
 greg.music.resources;bundle-version="1.0.0",
 org.eclipse.core.runtime,
 javazoom.jlgui.basicplayer,
 org.eclipse.e4.core.services;bundle-version="2.0.100"
Bundle-ClassPath: .,
 lib/jogg-0.0.7.jar,
 lib/jorbis-0.0.15.jar,
 lib/vorbisspi1.0.2.jar
Import-Package: javax.annotation;version="1.0.0",
 javax.inject;version="1.0.0",
 org.eclipse.e4.core.di.annotations

Matching build.properties

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.properties,\
               plugin.xml,\
               lib/jogg-0.0.7.jar,\
               lib/jorbis-0.0.15.jar,\
               lib/vorbisspi1.0.2.jar
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • 2
    There is no way to use maven then ? – Sou May 28 '20 at 13:36
  • 2
    I added the jars to the Bundle-Classpath. The Plug-in has no problems. Even though I still have the 'java.lang.NoClassDefFoundError'. – Sou May 28 '20 at 13:40
  • 1
    You can use Maven to do plug-in builds by using Eclipse Tycho. See for example [this tutorial](https://www.vogella.com/tutorials/EclipseTycho/article.html) – greg-449 May 28 '20 at 13:44
  • 1
    You must make sure the jars are included in the built plugin - make sure the build.properties includes the jars. – greg-449 May 28 '20 at 13:46