Skip to main content



      Home
Home » Modeling » EMF » Register EPackage in Xcore programatically in Standalone
Register EPackage in Xcore programatically in Standalone [message #1782143] Mon, 19 February 2018 07:23 Go to next message
Eclipse UserFriend
Hello,

I am trying to access the EPackage inside an XCore, so I can register it and load models that conform to the metamodel defined using xcore. This should work both when invoked from an Eclipse as in standalone (i.e. register the metamodel from a non-eclipse java application)

So far I have done:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
resourceSet.getPackageRegistry().put(XcorePackage.eINSTANCE.getNsURI(),	XcorePackage.eINSTANCE);
Resource metamodel = resourceSet.createResource(locationURI);
metamodel.load(Collections.EMPTY_MAP);
EPackage ePackage = (EPackage)EcoreUtil.getObjectByType(metamodel.getContents(), EcorePackage.Literals.EPACKAGE);


Currently I am getting an exception in the createResource call:
Quote:

java.lang.NoClassDefFoundError: org/eclipse/xtext/ui/shared/SharedStateModule
at org.eclipse.emf.ecore.xcore.ui.internal.XcoreActivator.getSharedStateModule(XcoreActivator.java:92)
at org.eclipse.emf.ecore.xcore.ui.internal.XcoreActivator.createInjector(XcoreActivator.java:64)
at org.eclipse.emf.ecore.xcore.ui.internal.XcoreActivator.getInjector(XcoreActivator.java:55)
at org.eclipse.emf.ecore.xcore.ui.XcoreExecutableExtensionFactory.getInjector(XcoreExecutableExtensionFactory.java:26)
at org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory.create(AbstractGuiceAwareExecutableExtensionFactory.java:51)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:262)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at org.eclipse.emf.ecore.plugin.RegistryReader$PluginClassDescriptor.createInstance(RegistryReader.java:167)
at org.eclipse.emf.ecore.plugin.RegistryReader$ResourceFactoryDescriptor.createFactory(RegistryReader.java:189)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.convert(ResourceFactoryRegistryImpl.java:92)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$2.delegatedGetFactory(ResourceSetImpl.java:458)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.getFactory(ResourceFactoryRegistryImpl.java:144)
at org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl.getFactory(ResourceFactoryRegistryImpl.java:85)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:431)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:423)
at org.eclipse.epsilon.emc.emf.EmfUtil.registerXcore(EmfUtil.java:212)
at org.eclipse.epsilon.emc.emf.EmfUtil.registerXcore(EmfUtil.java:201)
at org.eclipse.epsilon.emf.dt.EmfRegistryManager.registerMetamodel(EmfRegistryManager.java:142)
at org.eclipse.epsilon.emf.dt.EmfRegistryManager.addMetamodel(EmfRegistryManager.java:128)
at org.eclipse.epsilon.emf.dt.RegisterMetamodelHandler.execute(RegisterMetamodelHandler.java:40)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:282)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:264)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:488)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:433)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.handleWidgetSelection(AbstractContributionItem.java:454)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem$3.handleEvent(AbstractContributionItem.java:482)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1313)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3706)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)


The stack trace also suggests that in a standalone scenario I would need to add some "ui" dependencies, even though my java application does not do any UI per se.

Thanks for any info or pointers.

Cheers,
Re: Register EPackage in Xcore programatically in Standalone [message #1782145 is a reply to message #1782143] Mon, 19 February 2018 08:05 Go to previous messageGo to next message
Eclipse UserFriend
Your stack trace suggests you are launching an Eclipse application with a UI present.

To use Xcore stand alone you need to use org.eclipse.emf.ecore.xcore.XcoreStandaloneSetup.createInjectorAndDoEMFRegistration() to create an Injector that you use to create things that will in turn be properly injected. Probably best to look at some Xtext examples for how to use Xtext models stand alone.
Re: Register EPackage in Xcore programatically in Standalone [message #1782152 is a reply to message #1782145] Mon, 19 February 2018 10:03 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

Thanks for the information.
Yes, you are right that was from an Eclipse instance. I try the standalone setup for plain Java.

In the case of a UI present, any pointers on the error? My plugin has a dependency on xcore, but not on xtext. Do I need to also depend on xtext (and any other plugins?).

Cheers,
Re: Register EPackage in Xcore programatically in Standalone [message #1782153 is a reply to message #1782152] Mon, 19 February 2018 10:21 Go to previous message
Eclipse UserFriend
No, I don`t have much in the way of pointers, but if you look at the plugin-dependencies (in the Package explorer) of your model project you should expect need most (except the optional dependencies) in a stand alone application.
Previous Topic:synchronize form editor with emf editing domain
Next Topic:Keeping generated XSD free from ecore
Goto Forum:
  


Current Time: Wed Jul 23 11:03:38 EDT 2025

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

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

Back to the top