maven-processor-plugin 忽略 undefined symbol

标签 maven jpa-2.0 apt

我有 JPA 2 maven 项目,我想处理源以获得静态元模型。我做了什么,我拿了JBoss' static meta model processor并将其设置为在 generate-sources 阶段运行。现在,显然我有一些引用元模型的类,并且编译本身进展顺利。但是 maven-processor-plugin 本身会生成错误,提示它无法从元模型中找到符号,如下所示:

[INFO] --- maven-processor-plugin:2.2.4:process (process) @ ng-grid-java ---
[ERROR] diagnostic: c:\...\service\position\PositionSpecifications.java:13: cannot find symbol
symbol  : class Position_

这是合乎逻辑的,因为它实际上生成了这些类,但这是不正确的,因为它给本来正确的项目带来了错误。或者也许我用错了?我错过了什么吗?

更新:我已经能够通过使用配置参数outputDiagnostics来抑制错误输出,但我不确定这是正确的方法。

最佳答案

解决方案可以使用 build-helper-maven-plugin 将生成的类添加到项目类路径中,如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>artifactId</artifactId>
        <groupId>groupId</groupId>
        <version>1.0.0-SNAPSHOT</version>       
    </parent>
    <artifactId>jpa-metamodel-generation</artifactId>

    <dependencies>

        <!-- Hibernate JPA metamodel generator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>1.2.0.Final</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate.javax.persistence</groupId>
                    <artifactId>hibernate-jpa-2.0-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
            </plugin>

            <!-- Plugin to generate JPA metamodel -->
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.0.5</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>process-sources</phase>
                        <configuration>
                            <outputDirectory>${project.build.directory}/metamodel</outputDirectory>
                            <processors>
                                <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Build helper plugin to add generated sources to classpath -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/metamodel</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

关于maven-processor-plugin 忽略 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22634008/

相关文章:

java - maven-dependency-plugin 不排除匹配文件

mysql - 如何在 JPA(而不是 JPQL)中选择实体的一部分?

java - 如果我只有 ID,如何在 JPA2 中持久保存多对多集合?

docker - 在 Docker 镜像上安装 SSH

java - 嵌入式 ActiveMQ 代理需要哪些依赖项?

java - 使用最新的 Jetty 和 Jersey 在上传到 Heroku 的 WAR 文件中找不到依赖类

java - Websphere 特定 jar 的 POM 文件

criteria - Jpa QueryBuilder where子句中的多个表达式不起作用

python - 包 Python3.7 不可用

java - 贴切警告 : no annotation processor found