【问题标题】:Maven + MWE2Launcher + XText model refences an uncompiled Java ClassMaven + MWE2Launcher + XText 模型引用了一个未编译的 Java 类
【发布时间】:2019-05-06 19:49:56
【问题描述】:

我有一个关于 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
}

Java:

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 构建生成我的模型文件并编译 Java 文件就好了。

但现在我尝试使用 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 中工作,但我不知道如何。

【问题讨论】:

  • 这是不可能的。您必须将 java 类移动到单独的项目或预编译它
  • 您能否更具体地说明您在工作流程中的具体工作?

标签: java maven xtext


【解决方案1】:

我也有同样的问题。但我使用 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 取决于它。我还将预编译的类添加到类路径中。

【讨论】:

    猜你喜欢
    • 2015-10-15
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 2018-10-24
    • 1970-01-01
    相关资源
    最近更新 更多