Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource (error when trying to launch an ATL transformation from a Java program.)
Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1842902] Mon, 05 July 2021 18:41 Go to next message
nour nour is currently offline nour nourFriend
Messages: 19
Registered: April 2020
Junior Member
Hello everyone.

I am trying to execute an ATL transformation using a java standlone class called ATLauncher, which can be found at the following link.
https://github.com/guana/ATLauncher
The launcher works fine using the command line. But, right now I imported the launcher to my eclipse IDE and I am trying to launch my transformation using it and I am facing multiple issues with it.

Whenever i try to launch the transformation, i get the following error (/gui/mm/owls.ecore is the input ecore model for my transformation):

java.lang.RuntimeException: Cannot create a resource for '/gui/mm/owls.ecore'; a registered resource factory is needed
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
	at owlsPack.MyOWLSATLLauncher.launch(MyOWLSATLLauncher.java:70)
	at gui.myMaaS$6.actionPerformed(myMaaS.java:255)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6379)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)


I looked into it online and found out the following link:
https://wiki.eclipse.org/EMF/FAQ#How_do_I_use_EMF_in_standalone_applications_.28such_as_an_ordinary_main.29.3F
It explains that I must add the following line of code to enable the registration of the default resource factories (for my XMI file, which are the instance of my previously mentioned ecore model):

 resource factories are not registered in the standalone EMF environment


However, when I add the line of code, the Factory class is not recognized by the java class.
I tried to download the Resource interface package or import it. However, I could not find where to download it from or how to import it to my class.

Is the "Resource.Factory" interface outdated and deprecated?
if yes, what is the updated version of it?
if not, then how can I import/download/add this interface to my java program so it will be recognized and allow the launch of my transformation?
any available better solution the resolve the resource factory issue?

Thank you in advance.
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1842905 is a reply to message #1842902] Tue, 06 July 2021 04:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
You said this launcher things works fine from the command line. In that case you must have had everything needed to run EMF on the classpath, including the jars with the resource framework. You must set up this this same classpath for your project. But that appears not to have been done.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1842908 is a reply to message #1842905] Tue, 06 July 2021 05:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

No EMF is on the classpath since ResourceSetImpl is loaded, but your stack trace is very strange. I have never seen awt in use. It certainly doesn't look like a normal IDE launch where the resource factories are executed automatically by the extension points of OSGI plugins.

I would have to regard your launch as a custom standalone launch so you need to manually register all the EMF functionality just like any normal standalone application. You can practice this by writing a JUnit test that opens /gui/mm/owls.ecore and launching in Eclipse.

Regards

Ed Willink
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1842915 is a reply to message #1842908] Tue, 06 July 2021 08:15 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
Hi

I cloned the code from https://github.com/guana/ATLauncher, imported the project into my eclipse and was able to run it as an standalone program.

So this code seems to be OK, it has all the dependencies in the classpath and registers all the packages and factories required in the EMF registry (I am not a user of ATL so I cannot comment on that part of the code).

However, your stack trace doesn't corresponds to that code. So you have to check what you have changed.

The exception seems to be related to the load of a metamodel ('/gui/mm/owls.ecore'). This requires the ecore factory being registered.

This is done at the beginning of this method in ATLauncher :

	private String lazyMetamodelRegistration(String metamodelPath){
		
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
   	
	    ResourceSet rs = new ResourceSetImpl();
	    // Enables extended meta-data, weird we have to do this but well...
	    final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(EPackage.Registry.INSTANCE);
	    rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
	
	    Resource r = rs.getResource(URI.createFileURI(metamodelPath), true);
	    EObject eObject = r.getContents().get(0);
	    // A meta-model might have multiple packages we assume the main package is the first one listed
	    if (eObject instanceof EPackage) {
	        EPackage p = (EPackage)eObject;
	        System.out.println(p.getNsURI());
	        EPackage.Registry.INSTANCE.put(p.getNsURI(), p);
	        return p.getNsURI();
	    }
	    return null;
	}



Are you invoking that method in your code?

If you need further help you have to give more details on how are you starting your program, and what you have changed w.r.t the code in https://github.com/guana/ATLauncher

[Updated on: Tue, 06 July 2021 08:27]

Report message to a moderator

Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1843968 is a reply to message #1842915] Wed, 25 August 2021 18:14 Go to previous messageGo to next message
nour nour is currently offline nour nourFriend
Messages: 19
Registered: April 2020
Junior Member
Hello,
Thank you Ed and German for your answers.
It has been quite a long time since I posted this issue and I could not get back to it for several reasons that occurred in my life.

With regards to my launch, indeed, it was not a regular launch and I apologize for not mentioning that in the first post.
What I tried to achieve is GUI (graphical user interface) from which I will be able to run the transformation code by pressing a "transform" button.
I designed my interface and I used JButton to create my button (called "transformer", which will execute the ATLauncher code (the edited version of the class according to my model) and transform an input file conformant to the input meta-model and produces the output model.

The edited version of the ATLauncher class Is called "MyOWLSATLLauncher" and in my GUI class, I created an instance of this class, which I called "owlsLaunch".
So, in the "actionPerformed" method of the "transformer" button, I wrote a piece of code:
1) I called the "launch" method from the "MyOWLSATLLauncher" class, this method is the one that launches the transformation according to my understanding ​of the ATLauncher code.
​2) I tried to pass the required parameters to the "launch" method which are my input model, input metamodel, output model, output metamodel, the transformation folder, and the transformation.
The code is as follow
transformer.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
			
				try {
					
   				//owlsLaunch.launch(OUT_METAMODEL, IN_MODEL, IN_METAMODEL, IN_MODEL, TRANSFORMATION_MODULE, TRANSFORMATION_DIR); (this is the original code for the launch method)
                              owlsLaunch.launch("./mm/owls.ecore", "./mo/instance.xmi", "./mm/gcsd.ecore", "./mo/res.xmi", "./transformation/","owlstransModi");	
		            System.out.println("done!!");
			
				}
				catch (Exception e1) {
					
			e1.printStackTrace();
			System.out.println("nope");
				}
			}
			
		});


When I run as a java application, I get my user interface, when I press the "transformer" button I get the following error (which I mentioned in the original post).

java.lang.RuntimeException: Cannot create a resource for '/gui/mm/owls.ecore'; a registered resource factory is needed
nope
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
	at owlsPack.MyOWLSATLLauncher.launch(MyOWLSATLLauncher.java:70)
	at gui.myMaaS$6.actionPerformed(myMaaS.java:254)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6379)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)


I hope I made things clearer by adding this post, if you require any more details or clarification, i will gladly provide that.
I hope you will be able to help me out solving this issue.
Thank you in advance.
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1843973 is a reply to message #1843968] Wed, 25 August 2021 20:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You need something like

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());


when running standalone to provide what extension points do for free.

Regards

Ed Willink
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1843974 is a reply to message #1843973] Wed, 25 August 2021 21:42 Go to previous messageGo to next message
nour nour is currently offline nour nourFriend
Messages: 19
Registered: April 2020
Junior Member
Hello Ed,
thank you for the quick response.

However, could you please elaborate more, if possible?
Where exactly am I supposed to add these extensions? I mean, which part of my code? is it correct to add those right before calling the "launch" method from my GUI class?
or should I add them to my ATLauncher edited class?

Besides that, I still face the same issue when trying to download or import the Resource interface package. The Factory class is not recognized by the java class.
Is the "Resource.Factory" interface outdated and deprecated?
if yes, what is the updated version of it?
if not, then how can I import/download/add this interface to my java program so it will be recognized and allow the launch of my transformation?

Thank you in advance for the clarification.
Regards.
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1843991 is a reply to message #1843974] Thu, 26 August 2021 10:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

"at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
at owlsPack.MyOWLSATLLauncher.launch(MyOWLSATLLauncher.java:70)"

shows where your ResourcetSet(Impl) was inadequately configured. You need to place the "ecore" extension initialization before that.

Regards

Ed Willink
Re: Java.lang.RuntimeException: Cannot create a resource for 'xxxx'; a registered resource [message #1843993 is a reply to message #1843974] Thu, 26 August 2021 10:52 Go to previous message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
Hi

If you look at the original code of ATLLauncher.java

It has the following main :

	public static void main(String ... args){
		ATLLauncher l = new ATLLauncher();
		l.registerInputMetamodel(IN_METAMODEL);
		l.registerOutputMetamodel(OUT_METAMODEL);
		l.launch(IN_METAMODEL, IN_MODEL, OUT_METAMODEL, OUT_MODEL, TRANSFORMATION_DIR, TRANSFORMATION_MODULE);
	}


You have to do exactly the same (replacing of course the constants by your own paths) in your code.

If you look at the methods registerInputMetamodel and registerOutputMetamodel, they do exactly what Ed asked you to do.

Regards

G. Vega
Previous Topic:Ecore2Java ant task reports success, generates nothing.
Next Topic:Invoking XSDExporter (ModelConverter) programmatically
Goto Forum:
  


Current Time: Thu May 02 04:11:54 GMT 2024

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

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

Back to the top