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 |
nour nour 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 #1842915 is a reply to message #1842908] |
Tue, 06 July 2021 08:15 |
German Vega 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 |
nour nour 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.
|
|
| | | | |
Goto Forum:
Current Time: Sat Nov 11 09:26:08 GMT 2023
Powered by FUDForum. Page generated in 0.02111 seconds
|