15

我遵循了 JPA modelgen指南,并且能够生成我需要的规范元模型。有了这个 pom 设置:

<plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.0.6-redhat</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <outputDirectory>target/metamodel</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>target/metamodel</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

生成的源在指定目录中正确创建,我必须手动将其指定为 eclipse 项目类路径中的源才能使用它。当我触发 Maven 时,日志会显示cannot find symbol,或者duplicate class我仍然可以成功构建。所以我的问题是,这是创建元模型的预期/正确行为吗?还是我错过了 cofig 中的某些内容?谢谢

4

1 回答 1

16

我也在使用 JPA 元模型生成器,我没有你描述的问题,也许我的配置可以帮助,我看到了一些差异,第一个是maven-processor-plugin

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>2.1.0</version>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <processors>
          <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
        </processors>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-jpamodelgen</artifactId>
      <!--version>1.2.0.Final</version-->
      <version>4.3.4.Final</version>
    </dependency>
  </dependencies>
</plugin>

如您所见,我必须添加hibernate-jpamodelgen依赖项和处理器属性。

我不确定是否build-helper-maven-plugin有必要将生成的源目录添加到您的源路径。我没有使用它,它对我有用,但也许是因为我使用生成源的默认输出路径。

于 2013-02-13T08:52:18.850 回答