我刚刚将一个项目从 ant 转换为 maven,在构建 jar 时遇到错误,其行为就像源文件没有按正确的顺序编译一样。我有一个如下所示的枚举类型:
public enum LmsError implements ILmsError {
UC0001() {
@Override
public String msg() {
return this.getClass().getName() + "-" + this + ": constructor failed: ";
}
},
界面如下所示:
public interface ILmsError {
public abstract String msg();
}
...这是使用它的代码示例。 “throws”行是下面的错误消息所提示的行,但是如果我注释掉该语句,下次引用 msg() 方法时它就会收到类似的错误。使用枚举的哪个元素并不重要。
} catch (Exception e) {
throw new RuntimeException(LmsError.UC0001.msg() + "Unable to construct status based on " + codeEnumeration + ":" + e.getMessage(), e);
}
mvn 干净编译
[compiler:compile]
Compiling 129 source files to C:\bsaastad\workspaces\theportaltree\redirect\redirect-ejb\target\classes
-------------------------------------------------------------
COMPILATION ERROR :
-------------------------------------------------------------
com/theportaltree/redirect/status/RedirectStatus.java:[156,58] cannot find symbol
symbol : method msg()
location: class com.theportaltree.lms.LmsError
1 error
如果我在没有清理的情况下再次编译,我会得到类似的结果(有时需要两次额外的编译才能遍历所有文件):
[compiler:compile]
Compiling 89 source files to C:\bsaastad\workspaces\theportaltree\redirect\redirect-ejb\target\classes
[resources:testResources]
干净的编译。
如果我在失败后查看输出目录,我会发现生成的枚举类都不存在,这解释了错误。一旦我成功编译,枚举类就会按预期出现。
这都在同一个项目中,所以我不认为这是依赖问题。我刚刚将其从 ant 构建转换为 Maven(maven 新手),它已经编译好几年了,没有出现任何问题。这是 pom.xml 中的插件部分。是不是少了点什么?某些东西的版本错误?我很困惑:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<!-- put your configurations here -->
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<!-- javadoc configuration options here -->
</configuration>
</plugin>
</plugins>
</build>
任何帮助/想法将不胜感激。
最佳答案
您是否在执行命令行 Maven 构建的同时运行 IDE?
我发现有时如果您的 IDE 是 Maven 感知的(例如带有 m2Eclipse 插件的 Eclipse),您可能会在两个“竞赛”Maven 引擎之间发生不希望的交互。
如果关闭 IDE 会产生可靠的干净构建,请检查其配置选项 - 它可能会轮询文件系统以进行更改,这将依次启动(干净?)构建。
关于java - maven 似乎没有按顺序编译 - 找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12505721/