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 07:45 Go to next message
Johan Norberg is currently offline Johan Norberg
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 03:21 Go to previous messageGo to next message
Johan Norberg is currently offline Johan Norberg
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 06:15 Go to previous message
jy zhang is currently offline jy zhang
Messages: 19
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.
Previous Topic:uml2 docs, books
Next Topic:UML components: Add information about responsibility
Goto Forum:
  


Current Time: Fri Jul 25 02:54:55 EDT 2014

Powered by FUDForum. Page generated in 0.02022 seconds