我刚刚将一个项目从 ant 转换为 maven,并且在构建一个 jar 时出现错误,该 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 newbie),它已经编译了几年没有问题。这是 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>
任何帮助/想法将不胜感激。