如何多次执行Maven插件
我有两个数据库要生成hbm2java如何多次执行Maven插件,maven,reverse-engineering,Maven,Reverse Engineering,我有两个数据库要生成hbm2java <project> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version> 2.2</version> <exec
<project>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version> 2.2</version>
<executions>
<execution>
<id>db1</id>
<configuration>
<components>
<component>
<name>hbm2java</name>
...
</component>
</components>
<componentProperties>
...
<configurationfile>.../hibernate1.cfg.xml</configurationfile>
</componentProperties>
</execution>
<execution>
<id>db2</id>
<configuration>
<components>
<component>
<name>hbm2java</name>
...
</component>
</components>
<componentProperties>
...
<configurationfile>.../hibernate2.cfg.xml</configurationfile>
</componentProperties>
</execution>
</executions>
...
</plugin>
...
</plugins>
...
</project>
有什么想法吗?这些解释只与生命周期相关,这意味着您必须调用:
mvn process-resources
而不是简单地调用插件的目标。或更晚的阶段,如:
mvn compile
嗯,我不能通过生命周期来分离hbm2java的执行 我有一个使用自定义配置文件“生成”的解决方案:
生成
org.codehaus.mojo
hibernate3 maven插件
2.2
db1
hbm2java
...
...
…/hibernate1.cfg.xml
db2
hbm2java
...
...
…/hibernate2.cfg.xml
...
...
...
现在我需要执行3种不同的执行:
mvn安装-Dmaven.test.skip=true
编译反向工程策略mvn compile-P generate
生成类mvn测试
测试单元测试另外一个问题:我不喜欢通过编译生成类。我喜欢只通过hibernate3:hbm2java生成类。这些类将在生成资源期间生成,因为插件绑定到该生命周期阶段。此外,如果您进行mvn清理,那么生成的所有类都将被删除,因此最好坚持使用maven生命周期,并让hibernate插件在生命周期中生成类。通过您喜欢的方式进行的目标呼叫生成是不可能的。听起来有点像你不了解生命周期。在生命周期中不允许生成的原因是什么?我为生成指定了反向策略。这个策略必须首先编译!如果我执行maven清理,则ReverseStragy将不再可用,构建将失败!看到完整的pom会很有帮助,因为听起来你的构建有基本的问题。Maven中所有生成器的用途是在generate resources/generate sources生命周期内生成,并让编译器插件编译生成的源代码。您已经拥有了所有需要的信息。数据库并不总是可访问的,并且源代码被签入到subversion中,因此hbm2java只有在db可用的情况下才能运行。事实太多,问题太具体了。
mvn compile
<project>
<profiles>
<profile>
<id>generate</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>db1</id>
<configuration>
<components>
<component>
<name>hbm2java</name>
...
</component>
</components>
<componentProperties>
...
<configurationfile>.../hibernate1.cfg.xml</configurationfile>
</componentProperties>
</execution>
<execution>
<id>db2</id>
<configuration>
<components>
<component>
<name>hbm2java</name>
...
</component>
</components>
<componentProperties>
...
<configurationfile>.../hibernate2.cfg.xml</configurationfile>
</componentProperties>
</execution>
</executions>
...
</plugin>
...
</plugins>
</build>
</profile>
</profiles>
...
</project>