Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » NoClassDefFoundError while launching jar in command line
NoClassDefFoundError while launching jar in command line [message #1794157] Fri, 24 August 2018 15:40 Go to next message
Maude Sabourin is currently offline Maude SabourinFriend
Messages: 11
Registered: May 2018
Junior Member
My problem is very similar to the one here , but since the only solution is related to Maven (which I'm not using), I decided to write another post.

I have a full EMF project (Ecore, Emfatic, Genmodel and Eugenia) which generates EObjects and a XML version of a GMF.

When I run the project in Eclipse, everything works.

However, I need to execute this project in command line. When I write
java -jar fullpath.jar

I get
Unable to initialize the principal class mainclass
Caused by : java.lang.NoClassDefFoundError : org/eclipse/emf/ecore/resource/ResourceSet


Obviously in my code I do the following
import org.eclipse.emf.ecore.resource.ResourceSet;


Some readings online made me think it could be linked to the stack, but it seems more like a problem linked to dependencies.

Note :
When making the JAR, I couldn't include the .diagram project because of various errors such as
Problem writing project.tests/.classpath to JAR : duplicate entry : .classpath
Problem writing project.diagram/.plugin.xml to JAR : duplicate entry : .plugin.xml
Re: NoClassDefFoundError while launching jar in command line [message #1794161 is a reply to message #1794157] Fri, 24 August 2018 17:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Java requires that you enumerate all libraries that you use on the classpath. You can get some clues as to what you have omitted from

https://wiki.eclipse.org/EMF/FAQ#I_want_to_use_EMF.2C_SDO.2C_or_XSD_in_my_standalone_project.2C_or_include_only_a_working_subset_of_the_code._What_libraries_.28jar_files.29_do_I_need_in_my_CLASSPATH.3F

but that was many releases ago, so of course you must change all the versions, and again each release. Really tedious. If you use the plugin MANIFEST,MF Eclipse does it all for you.

Regards

Ed Willink
Re: NoClassDefFoundError while launching jar in command line [message #1794162 is a reply to message #1794161] Fri, 24 August 2018 18:28 Go to previous messageGo to next message
Maude Sabourin is currently offline Maude SabourinFriend
Messages: 11
Registered: May 2018
Junior Member
Thanks for the quick reply, I will definitely look closely into the link you provided and import what's needed.

When you are talking about the MANIFEST.MF plugin, do you mean this one ?

When making the JAR, I specified I wanted the manifest to be generated and gave the main class. Did I skip an important step there?
Re: NoClassDefFoundError while launching jar in command line [message #1794163 is a reply to message #1794162] Fri, 24 August 2018 19:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you use the EMF New Project wizard you will get a MANIFEST.MF automatically.

Regards

Ed Willink
Re: NoClassDefFoundError while launching jar in command line [message #1794168 is a reply to message #1794163] Fri, 24 August 2018 23:14 Go to previous messageGo to next message
Maude Sabourin is currently offline Maude SabourinFriend
Messages: 11
Registered: May 2018
Junior Member
I have tried using the Manifest.Mf already present in the project, but I get the same error.

The dependencies window clearly show that emf.ecore is a required plug-in.
(see attachment 1)

Below is the full Manifest text, the Require-Bundle shows emf.ecore.

Manifest-Version: 1.0
Main-Class: canard.tool.CanardTool
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: geodes.canard;singleton:=true
Automatic-Module-Name: geodes.canard
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: canard,
 canard.impl,
 canard.util
Require-Bundle: org.eclipse.core.runtime,
 org.eclipse.emf.ecore;visibility:=reexport
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.emf.ecore.xmi.impl


I will attempt your second solution and see if this gives better result.
Re: NoClassDefFoundError while launching jar in command line [message #1794172 is a reply to message #1794168] Sat, 25 August 2018 05:21 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You need to use Run As->Java Application to get the classpath built for you.

(The next version of Eclipse, via [1], should enable you to use the automatically created launch configuration to give you a command line that you can cut and paste into a naked OS command line.).

Regards

Ed Willink

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=537879,
Previous Topic:Custom icons under Oxygen
Next Topic:Tips/Advices to change EMF code generator behaviours
Goto Forum:
  


Current Time: Thu Mar 28 18:16:47 GMT 2024

Powered by FUDForum. Page generated in 0.03339 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top