Maven-Hibernate3プラグインを使用してソースを生成します
-
12-10-2019 - |
質問
他のソースファイルを生成することに加えて、DAOクラスの1つの工場クラス、Daofactory.javaを生成したいと思います。私はその目的のためにHBMTemplateを使用しています - 自分の *.ftlファイルを使用しています。問題は、(私が正しく理解しているように)データベース内の各エンティティに対してファイルが生成されることです。そのファイルを1回だけ生成することは可能ですか?
私のpom.xmlの一部:
<execution>
<id>hbmtemplate0</id>
<phase>generate-sources</phase>
<goals>
<goal>hbmtemplate</goal>
</goals>
<configuration>
<components>
<component>
<name>hbmtemplate</name>
<outputDirectory>src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<revengfile>/src/main/resources/hibernate.reveng.xml</revengfile>
<propertyfile>src/main/resources/database.properties</propertyfile>
<jdk5>false</jdk5>
<ejb3>false</ejb3>
<packagename>my.package.name</packagename>
<format>true</format>
<haltonerror>true</haltonerror>
<templatepath>src/main/resources/reveng.templates/</templatepath>
<filepattern>DAOFactory.java</filepattern>
<template>DAOFactory.java.ftl</template>
</componentProperties>
</configuration>
</execution>
解決
a) 通常、生成されたコードは入りません src/main/java
!!!! 使用する target/generated-sources/somefoldername
(というより: ${project.build.directory}/generated-sources/somefoldername
) 代わりは!それ以外の場合、生成されたコードはSCMになり、物事が面倒になります。経験則として: 編集するものはすべてSRCにあり、Mavenが作成または編集するものはすべてターゲットにあります.
Hibernate Toolsが生成されたソースディードをコンパイラのソースルーツに自動的に追加しない場合、でそれを行うことができます buildhelper-maven-plugin
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-source</id>
<phase>process-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>
${project.build.directory}/generated-sources/somefoldername
</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
b)単一のクラスに制限することはできないようです。したがって、あなたができることの1つは、必要のない生成されたJavaファイルを削除することです。そのようなことをする標準的な方法は、Antrunプラグインを使用することです。
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>process-sources</phase>
<configuration>
<target>
<delete>
<fileset
dir="${project.build.directory}/generated-sources/somefoldername"
includes="**/*.java" excludes="**/ClassYouWantToKeep.java" />
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
所属していません StackOverflow