首页 > 解决方案 > 如何使用 Maven 包阶段调用 exec-maven-plugin 目标?

问题描述

我已经在我的模块的 pom.xml 文件中配置了 exec-mavein-plugin ,但有些地方不太对劲。

我可以调用目标目录mvn exec:exec,它可以正常工作并创建一个可执行文件。

我相信它已正确配置为附加到阶段。但是当调用包阶段时,不会创建输出文件。我希望对配置的一个小调整可以解决它。

这是 pom.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.exache.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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    ...
  </parent>

  <artifactId>rmqcm</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>rmqcm</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>3.0.0</version>
      <type>maven-plugin</type>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        ...
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>3.0.0</version>
          <executions>
            <execution>
              <id>Create Executable</id>
              <phase>package</phase>
              <goals>
                <goal>exec</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <executable>${project.basedir}/scripts/make_rmqcm.bat</executable>
            <arguments>
              <argument>${project.basedir}\scripts\executable_java_stub.sh</argument>
              <argument>${project.build.directory}\${project.build.finalName}.jar</argument>
              <argument>${project.build.directory}\${project.name}</argument>
            </arguments>
          </configuration>
        </plugin>        
      </plugins>
    </pluginManagement>
  </build>
</project>

我感谢您的帮助。

拉斯彼得森

标签: javamavenexec-maven-plugin

解决方案


推荐阅读