java - Maven 与 Ant : exec Command line

标签 java maven ant

我想通过运行 pom.xml 中的 ant 任务来检索我的计算机的序列号。

<profile>
        <id>generate-license</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <configuration>
                                <tasks>
                                    <exec executable="wmic bios get serialnumber"
                                          resultproperty="serialNumber"
                                          failonerror="false" />
                                    <echo message="Serial number: ${serialNumber}" />
                                </tasks>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

我在编译阶段执行maven,结果如下:

[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks

主要:

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:48.264s
[INFO] Finished at: Wed May 27 10:17:57 GMT+01:00 2015
[INFO] Final Memory: 11M/121M
[INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project runner: An Ant BuildException has occured: Execute failed: java.io.IOExcept ion: Cannot run program "wmic bios get serialnumber": CreateProcess error=2, Le fichier spÚcifiÚ est introuvable
[ERROR] around Ant part ...... @ 4:100 in C:\xxx\yyy\target\antrun\build-main.xml

最佳答案

您可以尝试使用以下语法来传递参数吗?

<exec executable="wmic" resultproperty="serialNumber" failonerror="false">
      <arg value="bios" />
      <arg value="get" />
      <arg value="serialnumber" />
</exec>

关于java - Maven 与 Ant : exec Command line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30478428/

相关文章:

javascript - Ant 目标依赖于 gulp 任务

Apache Ant 区别 - exec 与 apply

java/ant jar 文件 SecurityException

java - 如何使用基于 "external"值的比较器创建 TreeMap

maven - 具有相同发布版本的 2 个不同功能分支的 SNAPSHOT 版本是什么

java - 从 Maven : "The parameters ' mainClass' for goal org. codehaus.mojo :exec-maven-plugin:1. 6.0 中的测试范围运行 main:java 丢失或无效”

java - 带注释 Controller 的 SpringMVC : requested resource is not available

java - JODA api 在时区之间转换日期

java - Maven - Spring RequestMapping 404 错误

java - Maven (eclipse) 使用阴影 jar 代替原始 jar