Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Problem loading UML in stand alone application(Problem to load an UML model in a stand alone application)
Problem loading UML in stand alone application [message #846630] Mon, 16 April 2012 11:45 Go to next message
Johan Norberg is currently offline Johan NorbergFriend
Messages: 5
Registered: April 2012
Location: Sweden
Junior Member
Hey,

This might be a simple problem, but I've had no success solving it so far, even though I tried a couple of different solutions found on this forum and in the EMF FAQ. But back to the problem at hand.

I'm trying to load an UML model in a stand alone application, but for most of the solutions I've tried I've gotten the following result: "NoClassDefFoundError".


I'm using the following code
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;


public class ModelCode {

	private URI typesUri = null;
	
	public Model getModel(String pathToModel) {
		
		typesUri = URI.createFileURI(pathToModel);
		ResourceSet set = new ResourceSetImpl();
	
		set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
			
		set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
		UMLPackage.eINSTANCE.eClass();
	
		set.createResource(typesUri);
		Resource r = null;
		r = set.getResource(typesUri, true);
		
        	Model m = (Model) EcoreUtil.getObjectByType(r.getContents(), UMLPackage.Literals.MODEL);
		
		return m;
	}
}


When debugging I'm encountering the error at "r = set.getResource(typesUri, true);". The following is the error message I'm getting when trying to run this code.

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/uml2/common/util/CacheAdapter
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.getCacheAdapter(ElementImpl.java:818)
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.eNotificationRequired(ElementImpl.java:955)
	at org.eclipse.uml2.uml.internal.impl.NamedElementImpl.setName(NamedElementImpl.java:267)
	at org.eclipse.uml2.uml.internal.impl.PackageImpl.eSet(PackageImpl.java:1455)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1162)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2658)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2717)
	at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:85)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2193)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTypeName(XMLHandler.java:2096)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2031)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:134)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1814)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1023)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:169)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at javax.xml.parsers.SAXParser.parse(Unknown Source)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:368)
	at backboneCode.ModelCode.getModel(ModelCode.java:33)
	at eArCon.application.E_ArConHandler.main(E_ArConHandler.java:37)
Caused by: java.lang.ClassNotFoundException: org.eclipse.uml2.common.util.CacheAdapter
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 39 more


Any help will be appreciated.
Thanks!
Re: Problem loading UML in stand alone application [message #847307 is a reply to message #846630] Tue, 17 April 2012 07:21 Go to previous messageGo to next message
Johan Norberg is currently offline Johan NorbergFriend
Messages: 5
Registered: April 2012
Location: Sweden
Junior Member
As I suspected it was a simple problem. It was due to an error of mine I did earlier when trying to solve the problem.
I had forgot to import a specific class, and a new pair of eyes helped me solve this problem.

If someone else have the same problem, this is the set of imports that I used.
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.common.util.CacheAdapter;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;


Other than that, the code is still the same.
Re: Problem loading UML in stand alone application [message #873474 is a reply to message #847307] Fri, 18 May 2012 10:15 Go to previous messageGo to next message
jy zhang is currently offline jy zhangFriend
Messages: 20
Registered: May 2012
Junior Member
Hi Johan,

I'm afraid you haven't added org.eclipse.uml2.common_1.6.0.v201105021727.jar to your classpath.
Best Regards.
Re: Problem loading UML in stand alone application [message #1725897 is a reply to message #873474] Tue, 08 March 2016 11:34 Go to previous messageGo to next message
Thomas Taeger is currently offline Thomas TaegerFriend
Messages: 19
Registered: February 2016
Junior Member
jy zhang wrote on Fri, 18 May 2012 10:15
org.eclipse.uml2.common_1.6.0.v201105021727.jar to your classpath


That was in the year 2011. In 2016 adding
org.eclipse.uml2.common_2.1.0.v20160201-0816.jar
instead does not resolve the import statement anymore.

Does anybody know which actual jar we have to add today for resolving
import org.eclipse.uml2.common.util.CacheAdapter; ?

Regards
Thomas
Re: Problem loading UML in stand alone application [message #1725905 is a reply to message #1725897] Tue, 08 March 2016 12:51 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You really should not use explicit JARs; they keep changing. Use a
tchnology such as MANIFEST.MF that sorts it out for you.

You can see the JAR using Navigate->Open Type Hierarchy, or Show
In->Package EXplorer.

For me, today, it's in org.eclipse.uml2.common_2.1.0.v20160201-0937.jar

Regards

Ed Willink



On 08/03/2016 11:34, Thomas Taeger wrote:
> jy zhang wrote on Fri, 18 May 2012 10:15
>> org.eclipse.uml2.common_1.6.0.v201105021727.jar to your classpath
>
>
> That was in the year 2011. In 2016 adding
> org.eclipse.uml2.common_2.1.0.v20160201-0816.jar instead does not
> resolve the import statement anymore.
>
> Does anybody know which actual jar we have to add today for resolving
> import org.eclipse.uml2.common.util.CacheAdapter; ?
>
> Regards
> Thomas
Previous Topic:UML diagram for model AND metamodel in MDA?
Next Topic:UML M2M
Goto Forum:
  


Current Time: Fri Mar 29 07:49:49 GMT 2024

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

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

Back to the top