Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » NoClassDefFoundError: org/eclipse/emf/ecore/EPackage(Reflection: Trying to get Class of generated Model Code Project during runtime )
NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1723722] Wed, 17 February 2016 11:16 Go to next message
Florian Goenner is currently offline Florian GoennerFriend
Messages: 15
Registered: December 2015
Junior Member
Greetings!

I am currently trying to access the eInstance Field in order to get the corresponding EPackage of my generated Model Project. My Model Project is somewhere on my file system but not necessarily in my eclipse workspace.
However, when trying to access the class like this:

public static Object registerPackage(String rootPathBin, String basePackage, String projectName, String className) throws MalformedURLException{
		URLClassLoader urlClassLoader = URLClassLoader.newInstance(new URL[] {new URL(rootPathBin)});
		try{
			Class<?> generatedClassifierClass = urlClassLoader.loadClass(basePackage+"."+projectName+"."+className);
			Field field = generatedClassifierClass.getDeclaredField("eINSTANCE");
			@SuppressWarnings("unused")
			Object classifier = field.get(null);
			return classifier;
		}catch(ClassNotFoundException | NoSuchFieldException
				| SecurityException | IllegalArgumentException | IllegalAccessException  c){
			c.printStackTrace();
			return null;
		}
	}


I end up getting the following:

java.lang.NoClassDefFoundError: org/eclipse/emf/ecore/EPackage
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:810)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at at.jku.sea.cloud.gmf.adapter.plugin.cloudinteraction.ModelInteraction.registerPackage(ModelInteraction.java:68)
	at at.jku.sea.cloud.gmf.adapter.plugin.app.GMFApplication.start(GMFApplication.java:60)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: java.lang.ClassNotFoundException: org.eclipse.emf.ecore.EPackage
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:810)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 27 more


I am assuming that it has something to do with resolving the emf.ecore plugin.

Any help would be greatly appreciated!
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1723733 is a reply to message #1723722] Wed, 17 February 2016 12:59 Go to previous messageGo to next message
Florian Goenner is currently offline Florian GoennerFriend
Messages: 15
Registered: December 2015
Junior Member
Java Classloading can be complicated sometimes, however giving the URLClassLoader constructor a parent Classloader as an additional parameter solved the problem.
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1723843 is a reply to message #1723733] Thu, 18 February 2016 12:21 Go to previous messageGo to next message
Florian Goenner is currently offline Florian GoennerFriend
Messages: 15
Registered: December 2015
Junior Member
UPDATE: There still seem to be Errors occuring!

Specifially speaking, the call
final Resource resource = resSet.getResource(URI.createFileURI(filePath), true);


where filepath is "C:/Users/Florian/Desktop/workspace/at.jku.sea.cloud.gmf.adapter.plugin/test/default.mindmap" which is a diagram file, I made with the corresponding GMF graphical editor,
returns me the following stacktrace:

java.lang.NoClassDefFoundError: testpackage/mindmap/impl/MapImpl
	at testpackage.mindmap.impl.MindmapFactoryImpl.createMap(MindmapFactoryImpl.java:119)
	at testpackage.mindmap.impl.MindmapFactoryImpl.create(MindmapFactoryImpl.java:68)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createObject(XMLHelperImpl.java:885)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createObject(XMLHelperImpl.java:922)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2222)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1366)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:77)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:163)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1292)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at at.jku.sea.cloud.modeling.util.transformation.model.ModelTransformation.transformECoreFile(ModelTransformation.java:48)
	at at.jku.sea.cloud.gmf.adapter.plugin.cloudinteraction.ModelInteraction.checkInModel(ModelInteraction.java:60)
	at at.jku.sea.cloud.gmf.adapter.plugin.app.GMFApplication.start(GMFApplication.java:66)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: java.lang.ClassNotFoundException: testpackage.mindmap.impl.MapImpl
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 49 more


I am aware that I somehow have to make sure, that all the classes in my generated Mindmap Project are loaded during runtime, but I have absolutely no clue how to achieve that, especially, since I have no clue which Classloader is used during runtime that fails at resolving the dependencies. If anyone could give me a hint I'd be really thankful.

[Updated on: Thu, 18 February 2016 12:23]

Report message to a moderator

Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1723909 is a reply to message #1723722] Fri, 19 February 2016 04:34 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6385
Registered: July 2009
Senior Member
Am 17.02.2016 um 12:16 schrieb Florian Goenner:
> Greetings!
>
> I am currently trying to access the eInstance Field in order to get the corresponding EPackage of my generated Model
> Project. My Model Project is somewhere on my file system but not necessarily in my eclipse workspace.
Why are you dealing with class loaders at all? From your stack trace it seems you're running an Eclipse/OSGi
application. Why don't you deploy your generated models as plugins and leave class loading to OSGi?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



> However, when trying to access the class like this:
>
> public static Object registerPackage(String rootPathBin, String basePackage, String projectName, String className)
> throws MalformedURLException{
> URLClassLoader urlClassLoader = URLClassLoader.newInstance(new URL[] {new URL(rootPathBin)});
> try{
> Class<?> generatedClassifierClass = urlClassLoader.loadClass(basePackage+"."+projectName+"."+className);
> Field field = generatedClassifierClass.getDeclaredField("eINSTANCE");
> @SuppressWarnings("unused")
> Object classifier = field.get(null);
> return classifier;
> }catch(ClassNotFoundException | NoSuchFieldException
> | SecurityException | IllegalArgumentException | IllegalAccessException c){
> c.printStackTrace();
> return null;
> }
> }
>
> I end up getting the following:
>
>
> java.lang.NoClassDefFoundError: org/eclipse/emf/ecore/EPackage
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
> at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:810)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> at at.jku.sea.cloud.gmf.adapter.plugin.cloudinteraction.ModelInteraction.registerPackage(ModelInteraction.java:68)
> at at.jku.sea.cloud.gmf.adapter.plugin.app.GMFApplication.start(GMFApplication.java:60)
> at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
> at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
> Caused by: java.lang.ClassNotFoundException: org.eclipse.emf.ecore.EPackage
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:810)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> ... 27 more
>
>
> I am assuming that it has something to do with resolving the emf.ecore plugin.
> Any help would be greatly appreciated!
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1723979 is a reply to message #1723909] Fri, 19 February 2016 12:02 Go to previous messageGo to next message
Florian Goenner is currently offline Florian GoennerFriend
Messages: 15
Registered: December 2015
Junior Member
Eike,

My generated Model Classes are already within Plugin Projects, however as I am fairly new to Eclipse/OSGi Application Development I am not entirely sure how to solve my problem. Fact is, my Plugin Projects are generated into my workspace which I have access to in my running Eclipse Application. What I want to achieve is to load any arbitrary diagram file as an ecore Resource and work with it, but the classes of my Generated Plugin Projects don't seem to get loaded at all.
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1723995 is a reply to message #1723979] Fri, 19 February 2016 15:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29452
Registered: July 2009
Senior Member
Florian,

Normally you generate a model and the projects in which you generate the
code are deployed with the application. The plugin.xml of the model
project registers the model package and that registered package is
loaded using the class loader of that bundle. So I'm not sure what
you're trying to achieve with the code you showed in your first post.
What does your plugin.xml look like? Is that bundle deployed in your
running application? Are all the Java packages of the project exported
in the MANIFEST.MF of the model project?


On 19.02.2016 13:02, Florian Goenner wrote:
> Eike,
>
> My generated Model Classes are already within Plugin Projects, however
> as I am fairly new to Eclipse/OSGi Application Development I am not
> entirely sure how to solve my problem. Fact is, my Plugin Projects are
> generated into my workspace which I have access to in my running
> Eclipse Application. What I want to achieve is to load any arbitrary
> diagram file as an ecore Resource and work with it, but the classes of
> my Generated Plugin Projects don't seem to get loaded at all.
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1724130 is a reply to message #1723995] Sun, 21 February 2016 15:08 Go to previous messageGo to next message
Florian Goenner is currently offline Florian GoennerFriend
Messages: 15
Registered: December 2015
Junior Member
In my first post I showed a code snippet which is needed for accessing the eInstance Field of my generated MindmapPackage model class. Currently I am forced to use a predefined Interface for a program, which reads a generated diagram file, made with the GMF graphical editor and transforms it into some other project-related data structure. And this interface needs the value of the eInstance field (EPackage) as a parameter.

Ultimately, what I want to achieve is to read a diagram file - created with the GMF graphical editor - as an ecore Resource and access its contents. My application is currently running in the same workspace where all the projects are generated to. But because model, edit and editor projects are generated during runtime, I cannot deploy them with my application. (The task in the first place was to do everything during runtime)

[Updated on: Sun, 21 February 2016 15:09]

Report message to a moderator

Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1724132 is a reply to message #1724130] Sun, 21 February 2016 15:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5970
Registered: July 2009
Senior Member
Hi

You are not forced to use predefined Interfaces.

Since perhaps Eclipse 3.6, there has been support for dynamic loading of
plugins, so you could generate your plugin then load it. I've never
tried this.

More mundanely you can load your own generated classes. The main gotcha
is that ClassLoader has no unload method, so if you have old classes
lying around you may fnd that stale classes have been loaded before you
generate your new ones. The solution is to use a new ClassLoader to load
your new classes.

My code to do this is:

GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.codegen\src\org\eclipse\ocl\examples\codegen\dynamic\ExplicitClassLoader.java

It was inspired by:

http://www.toptal.com/java/java-wizardry-101-a-guide-to-java-class-reloading

For EMF editors, the recent revamp of Ecore Editor by the EMF Forms
project is very close to permitting a Reflective Ecore Editor, so you
may not need to generate it at all.

Regards

Ed Willink


On 21/02/2016 15:08, Florian Goenner wrote:
> In my first post I showed a code snippet which is needed for accessing
> the eInstance Field of my generated MindmapPackage model class.
> Currently I am forced to use a predefined Interface for a program,
> which reads a generated diagram file, made with the GMF graphical
> editor and transforms it into some other project-related data
> structure. And this interface needs the value of the eInstance field
> (EPackage) as a parameter.
> Ultimately, what I want to achieve is to read a diagram file, which
> was created with the GMF graphical editor as an ecore Resource and
> access its contents. My application is currently running in the same
> workspace where all the projects are generated to. But because model,
> edit and editor projects are generated during runtime, I cannot deploy
> them with my application. (The task in the first place was to do
> everything during runtime)
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1724243 is a reply to message #1724132] Mon, 22 February 2016 13:24 Go to previous messageGo to next message
Florian Goenner is currently offline Florian GoennerFriend
Messages: 15
Registered: December 2015
Junior Member
Quote:
You are not forced to use predefined Interfaces.


Since this is part of my Bachelors Degree Project I am, unfortunately

Quote:
Since perhaps Eclipse 3.6, there has been support for dynamic loading of
plugins, so you could generate your plugin then load it. I've never
tried this.


After a ton of searching I wasn't able to find any further information on this topic or any API regarding such a task. Could you possibly give me some input please?
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1724245 is a reply to message #1724243] Mon, 22 February 2016 13:40 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 22/02/2016 14:24, Florian Goenner wrote:
> Quote:
>> You are not forced to use predefined Interfaces.
>
>
> Since this is part of my Bachelors Degree Project I am, unfortunately
> Quote:
>> Since perhaps Eclipse 3.6, there has been support for dynamic loading
>> of plugins, so you could generate your plugin then load it. I've never
>> tried this.
>
>
> After a ton of searching I wasn't able to find any further information
> on this topic or any API regarding such a task. Could you possibly give
> me some input please?
Probably Ed refers to BundleContext.installBundle(). You get a
BundleContext in your plugin activator start/stop method.

Anyhow, it's not quite clear why you would want to do that. You are
aware that EMF has a dynamic editor available wich is afair close to
100% capable of what the default generated editor does.
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1773097 is a reply to message #1724243] Thu, 21 September 2017 13:21 Go to previous messageGo to next message
Jim Foscue is currently offline Jim FoscueFriend
Messages: 15
Registered: June 2012
Junior Member
Did you ever resolve this issue?

We are having the same issue when running inside Eclipse-Mars.2 (4.5.2). It can't find the org.eclipse.emf.common plugin when running.

Thanks in advance for any help.
Re: NoClassDefFoundError: org/eclipse/emf/ecore/EPackage [message #1774292 is a reply to message #1773097] Thu, 12 October 2017 13:48 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29452
Registered: July 2009
Senior Member
It's not clear where you're looking? The core EMF runtime is part of the Eclipse platform, so it's definitely there when the IDE is running.
Previous Topic:Repair broken inter-resource references
Next Topic:EMF project generating RCP plugin stuff
Goto Forum:
  


Current Time: Tue Jul 17 22:50:28 GMT 2018

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

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

Back to the top