Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Reading a model instance produces a ClassNotFoundException
Reading a model instance produces a ClassNotFoundException [message #831933] Thu, 29 March 2012 14:38 Go to next message
Daniel Engelhardt is currently offline Daniel EngelhardtFriend
Messages: 11
Registered: November 2010
Junior Member
Hello,

for background, I had a similar problem using M2T a couple of weeks ago, see http: //www.eclipse .org/forums/index.php/t/305782/

Now, I want to read the exact same model file and produce a 'Resource' (in Java).

As I learned from the thread above, I included the dependencies of the plugins, registered the Metamodel and the factory. Still, I get an error:

org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'Function' is not found or is abstract. (platform:/resource/test/models/My.test, 2, 145)

My Java code looks like this:
public static void main(String[] args) {
    	URI u=URI.createFileURI("D:/runtime-Eclipse/test_new/models/My.test");
    	
    	
    	MyPackage mp = MyPackage.eINSTANCE;
    	mp.eClass();
    	
    	EPackage.Registry.INSTANCE.put(MyPackage.eNS_URI, MyPackage.eINSTANCE);
    	//EPackage.Registry.INSTANCE.put(null, MyPackage.eINSTANCE); // Including this does not change anything ...
    	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("test", new MyResourceFactoryImpl());     	
    	                         System.out.println(EPackage.Registry.INSTANCE.getEPackage(MyPackage.eNS_URI).toString());
    	
    	Resource resource = new MyResourceImpl(u);
    	
    	try {
    		resource.load(Collections.EMPTY_MAP);    	
    		
    		System.out.println(resource.getAllContents().toString());
    		Produce d = new Produce();
    		//d.helper(r);    		
    	} catch(IOException io) {
    		System.out.println("Exception");
    		System.out.println(io.getMessage());
    	}
    
    	System.out.println(resource.getErrors());
    	
} 

This produces:
org.test.my.impl.MyPackageImpl@157fb52 (name: my) (nsURI: http: //www.test.org/my, nsPrefix: test)
Exception
Class 'Function' is not found or is abstract. (file:/D:/runtime-Eclipse/test_new/models/My.test, 2, 53)
[org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'Function' is not found or is abstract. (file:/D:/runtime-Eclipse/test_new/models/My.test, 2, 53)]


What else do I have to do?

- I registered the package.
- I included the dependancies
- I introduced an Extension Mapping to the correct factory (or: at least to the factory which worked in the MWE file)

I played around for the whole day and could not make it work.

Does anybody have further ideas?

Thank you very much in advance.

Best regards,
Daniel
Re: Reading a model instance produces a ClassNotFoundException [message #832158 is a reply to message #831933] Thu, 29 March 2012 21:08 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Daniel,

Comments below.

On 29/03/2012 10:38 AM, Daniel Engelhardt wrote:
> Hello,
>
> for background, I had a similar problem using M2T a couple of weeks
> ago, see http: //www.eclipse .org/forums/index.php/t/305782/
>
> Now, I want to read the exact same model file and produce a 'Resource'
> (in Java).
>
> As I learned from the thread above, I included the dependencies of the
> plugins, registered the Metamodel and the factory. Still, I get an error:
>
> org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'Function' is
> not found or is abstract. (platform:/resource/test/models/My.test, 2,
> 145)
>
> My Java code looks like this:
>
> public static void main(String[] args) {
> URI
> u=URI.createFileURI("D:/runtime-Eclipse/test_new/models/My.test");
>
>
> MyPackage mp = MyPackage.eINSTANCE;
> mp.eClass();
>
> EPackage.Registry.INSTANCE.put(MyPackage.eNS_URI,
> MyPackage.eINSTANCE);
> //EPackage.Registry.INSTANCE.put(null, MyPackage.eINSTANCE); //
> Including this does not change anything ...
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("test",
> new MyResourceFactoryImpl());
>
> System.out.println(EPackage.Registry.INSTANCE.getEPackage(MyPackage.eNS_URI).toString());
>
> Resource resource = new MyResourceImpl(u);
You should be using a resource set in general...
>
> try {
> resource.load(Collections.EMPTY_MAP);
>
> System.out.println(resource.getAllContents().toString());
> Produce d = new Produce();
> //d.helper(r);
> } catch(IOException io) {
> System.out.println("Exception");
> System.out.println(io.getMessage());
> }
> System.out.println(resource.getErrors());
>
> }
> This produces:
>
> org.test.my.impl.MyPackageImpl@157fb52 (name: my) (nsURI: http:
> //www.test.org/my, nsPrefix: test)
> Exception
> Class 'Function' is not found or is abstract.
> (file:/D:/runtime-Eclipse/test_new/models/My.test, 2, 53)
> [org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'Function' is
> not found or is abstract.
> (file:/D:/runtime-Eclipse/test_new/models/My.test, 2, 53)]
>
>
> What else do I have to do?
What does this file look like?

Try using Generate Test Code and looking at the generated
MyExample.java. That example should be able to read and write
conforming instances in a stand alone application.
>
> - I registered the package.
> - I included the dependancies
> - I introduced an Extension Mapping to the correct factory (or: at
> least to the factory which worked in the MWE file)
>
> I played around for the whole day and could not make it work.
>
> Does anybody have further ideas?
>
> Thank you very much in advance.
>
> Best regards,
> Daniel


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF] feature edit parameters incorrect in .genmodel
Next Topic:Get notified of executed command
Goto Forum:
  


Current Time: Fri Apr 26 23:39:43 GMT 2024

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

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

Back to the top