【问题标题】:Is there a way to execute a program in maven to help build your project?有没有办法在 Maven 中执行程序来帮助构建您的项目?
【发布时间】:2012-02-07 01:44:22
【问题描述】:

我目前正在开发一个项目,该项目使用一种工具,该工具采用以下示例 IDL 文件并从中生成大约 5 个 Java 类。

struct Example { int x; int y; };

有没有办法让 Maven 使用我们在构建时自动创建这些 Java 类的命令行工具?

【问题讨论】:

    标签: java maven maven-plugin


    【解决方案1】:

    这是使用Exec Maven Plugin 的示例。

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <!-- this execution happens just after compiling the java classes, and builds the native code. -->
                    <id>build-native</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>src/main/c/Makefile</executable>
                        <workingDirectory>src/main/c</workingDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    

    【讨论】:

      【解决方案2】:

      您可以使用maven-antrun-plugin 插件运行任意Ant tasks 甚至任何命令行程序:

      <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-antrun-plugin</artifactId>
                  <version>3.0.0</version>
                  <executions>
                      <execution>
                          <phase>generate-sources</phase>
                          <configuration>
                              <target>
                                  <exec executable="ls">
                                      <arg value="-l"/>
                                      <arg value="-a"/>
                                  </exec>
                              </target>
                          </configuration>
                          <goals>
                              <goal>run</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </build>
      

      使用此配置,您的命令行程序将在编译之前执行,因此生成的 Java 源代码将可用于其余代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-26
        相关资源
        最近更新 更多