在一个目标中结合许多Maven目标

sp0*_*00m 17 java maven

到现在为止,我正在使用该命令mvn clean compile hibernate3:hbm2java启动我的程序.有没有办法将这三个目标合并为一个,例如mvn runmvn myapp:run

mab*_*aba 18

与我的另一个答案完全不同的另一个解决方案是使用exec-maven-plugin带有目标的exec:exec.

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <executable>mvn</executable>
                <arguments>
                    <argument>clean</argument>
                    <argument>compile</argument>
                    <argument>hibernate3:hbm2java</argument>
                </arguments>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

然后你就像这样运行它:

mvn exec:exec
Run Code Online (Sandbox Code Playgroud)

通过这种方式,您不会更改任何其他插件,也不会绑定到任何阶段.


mab*_*aba 6

根据Hibernate3 Maven插件站点,默认情况下hbm2java目标会绑定到generate-sources阶段.

通常,您不必清理项目,而是运行增量构建.

无论如何,如果你加入maven-clean-pluginhibernate3-maven-pluginpom.xml,你会拥有这一切在一个命令.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>auto-clean</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>hbm2java</id>
                    <goals>
                        <goal>hbm2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

如果您希望在hibernate3-maven-plugin之后运行,compile只需将目标设置为,compile因为它将始终在默认阶段之后运行.

因此,只需运行一个命令即可运行所有目标:

mvn compile
Run Code Online (Sandbox Code Playgroud)

如果你因为任何原因不想清理那么只需输入:

mvn compile -Dclean.skip
Run Code Online (Sandbox Code Playgroud)


Igo*_*hyn 5

您还可以为 Maven 构建定义一个默认目标。然后您的命令行调用将如下所示

mvn
Run Code Online (Sandbox Code Playgroud)

定义默认目标

将以下行添加到您的 pom.xml 中:

<build>
    <defaultGoal>clean compile hibernate3:hbm2java</defaultGoal>
</build>
Run Code Online (Sandbox Code Playgroud)

  • 也可以将默认目标放入配置文件中,因此如果您不想修改默认构建,可以使用“mvn -Prun”运行程序。 (3认同)