2

I am trying to use the example org.eclipse.xtext.example.arithmetics.Arithmetics with xtext. I can run the Eclipse Application as described in the 5-minute tutorial and 15-minute tutorial, so the editor will do syntax checking.

But how do I actually use the model in a Java app? (I'm not talking about code generation)

I found this FAQ entry. But which .jar files do I need to include in my build path? There are a lot of unresolved classes here.

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.getResource(
    URI.createURI("platform:/resource/org.xtext.example.mydsl/src/example.mydsl"), true);
Model model = (Model) resource.getContents().get(0);
Jason S
  • 184,598
  • 164
  • 608
  • 970

2 Answers2

0

These are the dependencies I found:

<classpathentry kind="lib" path="D:/gabor/eclipse2/plugins/org.eclipse.emf.mwe.utils_1.2.1.v201112070431.jar"/>
<classpathentry kind="lib"  path="D:/gabor/eclipse2/plugins/org.eclipse.xtext_2.2.1.v201112130541.jar"/>
<classpathentry kind="lib" path="D:/gabor/eclipse2/plugins/org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar"/>
<classpathentry kind="lib" path="D:/gabor/eclipse2/plugins/org.eclipse.emf.common_2.7.0.v20120127-1122.jar"/>

And the dsl project with the generated sources of course. Not a nice solution, I pressed ctrl-shift-t, searched for the missing classes, and the list showed in which jars does eclipse find that class, and then I added that jar as External Jar to my classpath.

Gabor Farkas
  • 123
  • 1
  • 5
0

if you do not want to find all dependency jars yourself you can use Rightclick on Project -> Export -> Java -> Runnable Jar file as a help to collect all dependency jars

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32