繁体   English   中英

Maven + MWE2Launcher + XText 模型引用一个未编译的 Java 类

[英]Maven + MWE2Launcher + XText model refences an uncompiled Java Class

我有一个关于 XText/Maven 的问题。 我有一个 XText/Maven/Java 项目。

在这个项目中有 Xtext 模型和 Java 源文件。 一些模型文件引用了一些 Java 文件。 例如:

模型:

package a.b.c

import java.util.List
import x.y.z.MyClass // <-- This is one of the Javafile in the same Project

dto MyModel
{
    MyClass myClass
}

爪哇:

package x.y.z;

public class MyClass
{
   String foo;
   String bar;
}

结构:

project
|
|----src/main
      |
      |---/java/x/y/z/MyClass.java
      |
      |---/model/a/b/c/MyModel.dto
      |
      |---/gen/a/b/c/MyModel.java <-- here goes the generated Javafile from the Model

我已经设法编写了一个 Xtext/Eclipse 插件,所以 Eclipse 构建生成了我的模型文件并编译了 Javafiles 就好了。

但现在我尝试用 Maven 构建项目。 我管理已经通过使用类的 mwe2 工作流完成了生成过程

org.eclipse.emf.mwe2.launch.runtime.MWE2Launcher

和其他模型文件生成得很好,但 MyModel 引用了一个尚未编译的 Java 类,因此未找到:

[ERROR] Execution Failed: Problems running workflow my.company.model.xtext.domainmodel.generator: Validation problems:
[ERROR] 49 errors:
[ERROR] MyModel.dto - <path>/model/a/b/c/MyModel.dto
[ERROR] 4: x.y.z.MyClass cannot be resolved to a type.
...

所以错误本身很清楚。 我尝试成功地首先预编译 Java 文件并将它们添加到类路径中。 但是我有很多这样的问题,我希望这是一种更好的方式来告诉 Xtext/Mwe2Launcher 它应该引用所需的 Java 文件。 因为它已经以某种神奇的方式在 Eclipse 中运行,但我不知道如何运行。

我也有同样的问题。 但我使用 Gradle 而不是 Maven。 但是它可能对某人仍然有用:

task precompile(type: JavaCompile) {
    source = 'src/main/java'
    classpath = sourceSets.main.compileClasspath
    destinationDir = sourceSets.main.java.outputDir
}

task generateXtextLanguage(type: JavaExec) {
    dependsOn precompile
    main = 'org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher'
    args += "src/main/mwe2/...your_path_here.../generate.mwe2"
    classpath = layout.files(configurations.mwe2, sourceSets.main.java.outputDir)
    inputs.file 'src/main/mwe2/...your_path_here.../generate.mwe2'
    inputs.dir 'src/main/xcore'
    outputs.dir 'target/generated-sources/xtext-gen'
}

我添加了precompile任务。 generateXtextLanguage依赖于它。 我还向类路径添加了预编译类。

暂无
暂无

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

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