java - 我需要从 maven 执行批处理文件,它将采用 2 个参数并且应该从 pom.xml 传递

标签 java maven

我需要从 maven 执行批处理文件,它将采用 2 个应该从 pom 文件传递​​的参数。我能够执行批处理文件但无法设置参数。 请告诉我如何设置批处理文件的参数

我正在写下面的代码:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
            <id>runbatchfile</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>cmd</executable>
        <workingDirectory></workingDirectory>
        <arguments>
            <argument>/C</argument>
            <argument>D:\ITAS_TOI\toi20161207T072319Z\toi\ITAS.bat</argument>
        </arguments>
    </configuration>
</plugin>

编辑 :来自以下 OP 的评论:

我尝试了下面的代码,但它给了我以下错误:

The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.2:exec are missing or invalid

<configuration>
  <tasks>
    <exec dir="D:\ITAS_TOI\toi-20161207T072319Z\toi" executable="D:\ITAS_TOI\toi-20161207T072319Z\toi\ITAS‌​.bat" failonerror="true">
      <arg line="$testingDevice $executedon" />
    </exec>
  </tasks>
</configuration>

最佳答案

您可以在 pom.xml 中指定如下参数:

<properties>
    <argument1></argument1>
    <argument2></argument2>
</properties>

....

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
            <id>runbatchfile</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
         <executable>cmd</executable>
         <workingDirectory></workingDirectory>
         <arguments>
            <argument>${argument1}</argument>
            <argument>${argument2}</argument>
            <!--you can rename accordinlgy-->
         </arguments>
    </configuration>
</plugin>

然后在命令行上执行如下:

mvn exec:java -Dargument1=/C -Dargument2=D:\ITAS_TOI\toi-20161207T072319Z\toi\ITAS‌​.bat

关于java - 我需要从 maven 执行批处理文件,它将采用 2 个参数并且应该从 pom.xml 传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41044829/

相关文章:

java - 使用访问策略向用户配置 Active Directory 帐户时出错

java - Jetty:隐藏 URL 中的端口号

maven - 描述为 “:artifactId:version”的Maven Artifact 的默认groupId是什么?

maven - 如何将我的外部 jar 文件添加到类路径

maven - Maven中的冲突库

tomcat hbase jar 包含

java - 缩放 ImageView 的最佳方式

java - Eclipse 的 Jess 插件无法工作?并且未安装

java - 类重命名后 Netbeans 部署失败

java - JVM 中裸 java.lang.Object 的实际大小