使用ant构建xtext项目时出错:语法类的生成失败

我正在为我的学士论文开发一个用于eclipse应用程序的xtext插件项目.

我想在运行时使用执行Mwe2Launcher类的ant脚本执行’Generate Xtext Artifacts’,并在temp文件夹中进行生成.

我写了一个Activator来在temp文件夹中创建一个项目文件夹并复制mwe2文件,我的语法文件和ant脚本.

执行Ant脚本会导致此错误:

osgi> start 360
gen:
 [java] 0    INFO  StandaloneSetup    - Registering platform uri 'C:\Foo-test'
 [java] 2461 INFO  DirectoryCleaner   - Cleaning C:\Foo-test\org.xtext.example.foobar\..\org.xtext.example.foobar\src-gen
 [java] 2503 INFO  DirectoryCleaner   - Cleaning C:\Foo-test\org.xtext.example.foobar\..\org.xtext.example.foobar.ui\src-gen
 [java] 3056 INFO  LanguageConfig     - generating infrastructure for org.xtext.example.foobar.Foo with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, ParseTreeConstructorFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment
 [java] 6253 INFO  GenModelHelper     - Registered GenModel 'http://www.xtext.org/example/foobar/Foo' from 'file:/C:/Foo-test/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/Foo.genmodel'
 [java] org.eclipse.emf.common.util.WrappedException: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/FooPackage.java' is unmapped
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:1112)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenPackageGeneratorAdapter.generatePackageInterface(GenPackageGeneratorAdapter.java:467)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenPackageGeneratorAdapter.generateModel(GenPackageGeneratorAdapter.java:219)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter.doGenerate(GenBaseGeneratorAdapter.java:221)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generate(AbstractGeneratorAdapter.java:290)
 [java]     at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:617)
 [java]     at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:528)
 [java]     at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.doGenerate(EcoreGeneratorFragment.java:144)
 [java]     at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.generate(EcoreGeneratorFragment.java:211)
 [java]     at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
 [java]     at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:108)
 [java]     at org.eclipse.xtext.generator.Generator.generate(Generator.java:352)
 [java]     at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:126)
 [java]     at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
 [java]     at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
 [java]     at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
 [java]     at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
 [java]     at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:97)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:76)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
 [java] Caused by: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/FooPackage.java' is unmapped
 [java]     at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createOutputStream(PlatformResourceURIHandlerImpl.java:428)
 [java]     at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createOutputStream(ExtensibleURIConverterImpl.java:339)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.createOutputStream(AbstractGeneratorAdapter.java:1440)
 [java]     at org.eclipse.emf.mwe2.ecore.CvsIdFilteringGeneratorAdapterFactoryDescriptor$IdFilteringGenModelGeneratorAdapterFactory$IdFilteringGenPackageAdapter.createOutputStream(CvsIdFilteringGeneratorAdapterFactoryDescriptor.java:39)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:1104)
 [java]     ... 21 more
 [java] org.eclipse.emf.common.util.WrappedException: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Model.java' is unmapped
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:1112)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter.generateInterface(GenClassGeneratorAdapter.java:123)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter.generateModel(GenClassGeneratorAdapter.java:106)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter.doGenerate(GenBaseGeneratorAdapter.java:221)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generate(AbstractGeneratorAdapter.java:290)
 [java]     at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:617)
 [java]     at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:528)
 [java]     at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.doGenerate(EcoreGeneratorFragment.java:144)
 [java]     at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.generate(EcoreGeneratorFragment.java:211)
 [java]     at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
 [java]     at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:108)
 [java]     at org.eclipse.xtext.generator.Generator.generate(Generator.java:352)
 [java]     at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:126)
 [java]     at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
 [java]     at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
 [java]     at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
 [java]     at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
 [java]     at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:97)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:76)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
 [java] Caused by: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Model.java' is unmapped
 [java]     at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createOutputStream(PlatformResourceURIHandlerImpl.java:428)
 [java]     at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createOutputStream(ExtensibleURIConverterImpl.java:339)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.createOutputStream(AbstractGeneratorAdapter.java:1440)
 [java]     at org.eclipse.emf.mwe2.ecore.CvsIdFilteringGeneratorAdapterFactoryDescriptor$IdFilteringGenModelGeneratorAdapterFactory$IdFilteringGenClassAdapter.createOutputStream(CvsIdFilteringGeneratorAdapterFactoryDescriptor.java:73)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:1104)
 [java]     ... 21 more
 [java] org.eclipse.emf.common.util.WrappedException: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Greeting.java' is unmapped
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:1112)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter.generateInterface(GenClassGeneratorAdapter.java:123)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter.generateModel(GenClassGeneratorAdapter.java:106)
 [java]     at org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter.doGenerate(GenBaseGeneratorAdapter.java:221)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generate(AbstractGeneratorAdapter.java:290)
 [java]     at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:617)
 [java]     at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:528)
 [java]     at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.doGenerate(EcoreGeneratorFragment.java:144)
 [java]     at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.generate(EcoreGeneratorFragment.java:211)
 [java]     at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
 [java]     at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:108)
 [java]     at org.eclipse.xtext.generator.Generator.generate(Generator.java:352)
 [java]     at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:126)
 [java]     at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
 [java]     at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
 [java]     at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
 [java]     at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
 [java]     at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:97)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:76)
 [java]     at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
 [java] Caused by: java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Greeting.java' is unmapped
 [java]     at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createOutputStream(PlatformResourceURIHandlerImpl.java:428)
 [java]     at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createOutputStream(ExtensibleURIConverterImpl.java:339)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.createOutputStream(AbstractGeneratorAdapter.java:1440)
 [java]     at org.eclipse.emf.mwe2.ecore.CvsIdFilteringGeneratorAdapterFactoryDescriptor$IdFilteringGenModelGeneratorAdapterFactory$IdFilteringGenClassAdapter.createOutputStream(CvsIdFilteringGeneratorAdapterFactoryDescriptor.java:73)
 [java]     at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:1104)
 [java]     ... 21 more
 [java] 6768 INFO  EcoreGeneratorFragment - Diagnostic ERROR source=org.eclipse.emf.codegen.ecore code=0 Generating code data=[] [Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic ERROR source=org.eclipse.emf.codegen.ecore code=0 Generating Java interface org.xtext.example.foobar.foo.FooPackage failed with an unhandled exception data=[] [Diagnostic ERROR source=org.eclipse.emf.common code=0 IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/FooPackage.java' is unmapped data=[java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/FooPackage.java' is unmapped]], Diagnostic ERROR source=org.eclipse.emf.codegen.ecore code=0 Generating Java interface org.xtext.example.foobar.foo.Model failed with an unhandled exception data=[] [Diagnostic ERROR source=org.eclipse.emf.common code=0 IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Model.java' is unmapped data=[java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Model.java' is unmapped]], Diagnostic ERROR source=org.eclipse.emf.codegen.ecore code=0 Generating Java interface org.xtext.example.foobar.foo.Greeting failed with an unhandled exception data=[] [Diagnostic ERROR source=org.eclipse.emf.common code=0 IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Greeting.java' is unmapped data=[java.io.IOException: The path '/org.xtext.example.foobar/src-gen/org/xtext/example/foobar/foo/Greeting.java' is unmapped]], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[], Diagnostic OK source=org.eclipse.emf.common code=0 OK data=[]]
 [java] 10385 INFO  JavaValidatorFragment - generating Java-based EValidator API
 [java] 13246 INFO  Workflow           - Done. BUILD SUCCESSFUL Total time: 27 seconds

还没有生成未映射的“.java”文件.缺少整个“/src-gen/…../foobar/foo”文件夹.

我想这就是原因,应该修复什么.

我真的不知道,问题出在哪里.我已经在Eclipse forum中讨论过你可以找到build.xml但是对于另一个项目,还有一个Activator类来激活插件并执行复制并执行ant脚本,你也找到了我使用的mwe2文件.

最佳答案
您必须确保在工作流程中将临时文件夹注册为平台URI. Xtext使用EMF的平台:/ resource URI方案.因此,必须注册平台根,以便根据平台路径定义从文件系统上的绝对位置到逻辑位置的路径映射.您也可以尝试复制.project文件.我认为如果你已经将temp文件夹注册为平台路径,这将有所帮助.

转载注明原文:使用ant构建xtext项目时出错:语法类的生成失败 - 代码日志