Java Maven2绑定到自定义阶段

Java Maven2绑定到自定义阶段,java,maven-2,maven-plugin,Java,Maven 2,Maven Plugin,我有一个使用pom.xml定义的自定义插件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion

我有一个使用pom.xml定义的自定义插件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pram.plugintest</groupId>
  <artifactId>pram.plugintest</artifactId>
  <packaging>maven-plugin</packaging>
  <version>1.1-SNAPSHOT</version>
  <name>pram.plugintest Maven Mojo</name>
  <url>http://maven.apache.org</url>
  <build>
        <plugins>
            <plugin>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <goalPrefix>blah</goalPrefix>
                </configuration>
            </plugin>
        </plugins>
      <resources>
          <resource>
              <directory>src/main/resources</directory>
          </resource>
      </resources>
    </build>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
按预期在目标目录中创建文本文件。现在,我在pom中指定的资源目录中创建一个lifecycles.xml文件

<lifecycles>
    <lifecycle>
        <id>touch</id>
        <phases>
            <phase>
                <id>package</id>
                <executions>
                    <execution>
                        <goals>
                            <goal>touch</goal>
                        </goals>
                    </execution>
                </executions>
            </phase>
        </phases>
    </lifecycle>
</lifecycles>
但是,运行它会创建文本文件,但不会尝试运行
org.sonatype.mavenbook.weather.Main

这是正确的方法吗

最终,我希望在execmaven插件中有多个不绑定到默认阶段的执行部分。从逻辑上看,它是这样的

...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
        <id>test1</id>
        <phase>blah:touch</phase>
        <goals>
            <goal>java</goal>
        </goals>
        <configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
        </configuration>
    </execution>
<execution>
        <id>test2</id>
        <phase>blah:touch2</phase>
        <goals>
            <goal>java</goal>
        </goals>
        <configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.SomeOtherClass</mainClass>
        </configuration>
    </execution>
</executions>
</plugin>
...
。。。
org.codehaus.mojo
这似乎指出了如何做到这一点。

如果您只想在构建过程中执行插件,则不能使用exec maven插件,也不需要lifecycle.xml

要在特定的Maven阶段执行插件,只需添加

   <plugins>
        <plugin>
            <groupId>your.group.id</groupId>
            <artifactId>your.artifact.id</artifactId>
            <executions>
                <execution>
                    <id>unique-execution-id</id>
                    <goals>
                        <goal>the.goal.of.your.plugin</goal>
                    </goals>
                    <phase>maven.phase</phase>
                    <configuration>
                     ....
                    </configuration>
                </execution>
             </executions>
        </plugin>
   </plugins>

您的.group.id
? 

您不能为此使用exec maven插件,如果您只想在构建期间执行插件,则不需要lifecycle.xml

要在特定的Maven阶段执行插件,只需添加

   <plugins>
        <plugin>
            <groupId>your.group.id</groupId>
            <artifactId>your.artifact.id</artifactId>
            <executions>
                <execution>
                    <id>unique-execution-id</id>
                    <goals>
                        <goal>the.goal.of.your.plugin</goal>
                    </goals>
                    <phase>maven.phase</phase>
                    <configuration>
                     ....
                    </configuration>
                </execution>
             </executions>
        </plugin>
   </plugins>

您的.group.id

?

我想要实现的是在execmaven插件中有不同的执行部分链接到非默认阶段。我将在最初的帖子中对此进行扩展,我希望实现的是在execmaven插件中链接到非默认阶段的不同执行部分。我将在最初的帖子中对此进行扩展
   <plugins>
        <plugin>
            <groupId>your.group.id</groupId>
            <artifactId>your.artifact.id</artifactId>
            <executions>
                <execution>
                    <id>unique-execution-id</id>
                    <goals>
                        <goal>the.goal.of.your.plugin</goal>
                    </goals>
                    <phase>maven.phase</phase>
                    <configuration>
                     ....
                    </configuration>
                </execution>
             </executions>
        </plugin>
   </plugins>