简体   繁体   English

xtext:除了Eclipse编辑器外,如何使用语法?

[英]xtext: how to use grammar besides Eclipse editor?

I am trying to use the example org.eclipse.xtext.example.arithmetics.Arithmetics with xtext. 我正在尝试将示例org.eclipse.xtext.example.arithmetics.Arithmetics与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. 我可以按照5分钟教程15分钟教程中的描述运行Eclipse Application,因此编辑器将进行语法检查。

But how do I actually use the model in a Java app? 但是我实际上如何在Java应用程序中使用该模型? (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? 但是,我需要在构建路径中包括哪些.jar文件? 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);

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. 当然还有带有生成源的dsl项目。 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. 这不是一个很好的解决方案,我按了ctrl-shift-t,搜索了丢失的类,列表显示了在哪个jars eclipse中找到了该类,然后将该jar作为外部Jar添加到了我的类路径中。

如果您不想自己查找所有依赖项jar,则可以在Project-> Export-> Java-> Runnable Jar文件上单击鼠标右键,以帮助收集所有依赖项jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM