Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Use Xtext infrastructure in standalone application
Use Xtext infrastructure in standalone application [message #831242] Wed, 28 March 2012 16:59 Go to next message
Bastian Mueller is currently offline Bastian MuellerFriend
Messages: 4
Registered: March 2012
Junior Member

I defined a Ecore metamodel and created an Xtext grammar, that is importing it. Now I tried to create a standalone application that is able to load a file. When generating the metamodel from the grammar, it works just fine, but when importing a metamodel, there are issues with registering the generated model code.

I followed the suggestions in the Xtext FAQ ("How do I load my model in a standalone Java application?") and also tried to load the package and register the factory. However, after registering the factory, I get the following error:

Exception in thread "main" java.lang.ClassCastException:
  Test.impl.TestFactoryImpl cannot be cast to

The same problem seems to have been already discussed in the thread 657914
(sorry, the forum doesn't allow me to post links yet...)

Still, there's no solution. Trying the Impl versions of the classes results in the same issue. Right now the code for loading looks like this:
Injector injector = new TestDSLStandaloneSetup()
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);


  .put("test", TestFactory.eINSTANCE);

Resource resource =
  resourceSet.getResource(URI.createURI("samples/test.test"), true);

I attached a minimum workspace including the 3 projects (metamodel, Xtext grammar and standalone application), to illustrate the issue. It doesn't inlcude the dependencies, due to the size limit (, org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar, org.eclipse.emf.common_2.7.0.v20120127-1122.jar, org.eclipse.xtext_2.3.0.v201203201034.jar, org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar)

Re: Use Xtext infrastructure in standalone application [message #831248 is a reply to message #831242] Wed, 28 March 2012 17:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13416
Registered: July 2009
Senior Member

just make sure
- that you do NOT call Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("test", TestFactory.eINSTANCE);
- but call sth like EPackage.Registry.INSTANCE.put(MyDslPackage.eNS_URI, MyDslPackage.eINSTANCE); before calling the standalonesetup


Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Using xtext without eclipse
Next Topic:How to: xText-model->ecore model (?) -> generated text
Goto Forum:

Current Time: Thu Apr 02 00:15:08 GMT 2020

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

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

Back to the top