2


他のソース ファイルを生成するだけでなく、DAO クラスの 1 つのファクトリ クラス (DAOFactory.java) も生成したいと考えています。私はその目的のために hbmtemplate を使用しています - 私自身の *.ftl ファイルで。問題は、(私が正しく理解しているように)データベース内のエンティティごとにファイルが生成されることです。そのファイルを一度だけ生成することは可能ですか?

私の 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>
4

1 に答える 1

1

a)生成されたコードは通常は入りませんsrc/main/java!!!! target/generated-sources/somefoldername代わりに(またはむしろ:)を使用してください${project.build.directory}/generated-sources/somefoldername!そうしないと、生成されたコードがSCMに格納されてしまい、問題が発生します。経験則として、編集するものはすべてsrcにあり、mavenが作成または編集するものはすべてtargetにあります。

Hibernateツールが生成されたソースディレクトリをコンパイラのソースルートに自動的に追加しない場合は、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>
于 2011-01-18T15:15:21.430 に答える