Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext standalone application beginner tutorial
Xtext standalone application beginner tutorial [message #900652] Wed, 08 August 2012 01:01 Go to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Hello everybody,

I just jumped into the xtext project and I went through the different tutorials here

My goal is to use the parser generated by Xtext in my own java project so that I could invoke something like


and navigate the AST of myDSLString to do my own stuff.
However I could not found any stap-by-step tutorial on how to import the parser generated by xtext in my standalone java application. Any help is appreciated.

Thank you

[Updated on: Wed, 08 August 2012 01:01]

Report message to a moderator

Re: Xtext standalone application beginner tutorial [message #900859 is a reply to message #900652] Wed, 08 August 2012 18:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member

this highly depends on your needs: do you want to read a single file or a bunch.
do you want to use a mwe/mwe2 workflow ...
never the less as a starting point


Need training, onsite consulting or any other kind of help for Xtext?
Go visit or send a mail to

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Re: Xtext standalone application beginner tutorial [message #901104 is a reply to message #900859] Thu, 09 August 2012 19:43 Go to previous message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Thank you Christian, I was able to solve the problem and this is the guide step by step for the next one interested

1- Create your sample grammar in Xtext with the 5 minute tutorial (Cattura.png)
2- Create a run configuration for the project (Cattura1.png)
3- Export the project as a runnable jar in the lib folder of your standalone project (Cattura2.png+Cattura3.png)
4- I got warnings and incomprehensible stuffs, but it works even with them (Cattura4.png)
5- Add the jar to your standalone project (Cattura5.png)
6- Run with the code from the XText FAQ and check your greeting

		new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
		Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
		Resource resource = resourceSet.createResource(URI.createURI("file:/example.mydsl"));
		InputStream in = new ByteArrayInputStream("Hello World".getBytes());
		resource.load(in, resourceSet.getLoadOptions());
		Model model = (Model) resource.getContents().get(0);
		for(Greeting e:model.getGreetings()){

IMPORTANT: The extension in this line
Resource resource = resourceSet.createResource(URI.createURI("file:/example.mydsl"));

should be the same of the mwe2 workflow in the grammar project
var file.extensions = "mydsl"

  • Attachment: Cattura.PNG
    (Size: 131.57KB, Downloaded 545 times)
  • Attachment: Cattura1.PNG
    (Size: 183.55KB, Downloaded 581 times)
  • Attachment: Cattura2.PNG
    (Size: 178.97KB, Downloaded 456 times)
  • Attachment: Cattura4.PNG
    (Size: 213.19KB, Downloaded 484 times)
  • Attachment: Cattura5.PNG
    (Size: 176.46KB, Downloaded 448 times)
Previous Topic:Loading a resource
Next Topic:Make my model nodes implement an interface?
Goto Forum:

Current Time: Sat Nov 28 16:30:00 GMT 2020

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

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

Back to the top