生成的代码在maven编译过程中没有考虑到

时间:2011-08-07 19:39:18

标签: java generated-code maven-compiler-plugin

我有一个maven项目在编译过程中从注释处理器生成一个新类。该类已在/target/generated-sources/annotations/中成功生成,但未编译到.jar中。为什么呢?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>${project.build.source}</source>
        <target>${project.build.target}</target>
        <encoding>${project.build.sourceEncoding}</encoding>
        <compilerArgument>-Xlint</compilerArgument>
        <annotationProcessors>
                <annotationProcessor>net.preprocessing.MyAnnotationProcessor</annotationProcessor>
        </annotationProcessors>
    </configuration>
</plugin>

修改

这似乎是一个已知的bug。如果有人有可操作的解决方法,欢迎使用。

编辑2

昨天我已经进行了一些测试,但是故障单中建议的解决方法不起作用。我提供了一个测试用例。如果有人知道如何解决这个问题,欢迎。请记住,我是注释处理的新手,所以可能会有一些我不知道的东西。

2 个答案:

答案 0 :(得分:6)

我建议使用 maven-processor-plugin 而不是传递给maven编译器的'annotationProcessor'参数。

从我读过的内容来看,compilerArgumens似乎存在一些问题,当你使用maven-processor-plugin时会解决这些问题。

在这里,您可以找到有关maven-processor-plugin的更多信息:http://maven-annotation-plugin.googlecode.com/svn/docs/usage.html

以下是处理器插件如何替换compilerArguments的示例(该示例使用Hibernate Metamodel Generator,但对于所有类型的注释处理器,这看起来都是一样的......):http://relation.to/Bloggers/HibernateStaticMetamodelGeneratorAnnotationProcessor

答案 1 :(得分:1)

看来你所做的只是编译类而不是构建jar。 您需要使用Maven Jar Plugin 这是usage example