标签: exec-maven-plugin

运行exec-maven-plugin java时如何获取“ [DEBUG]执行命令行:”

我正在运行别人的pom.xml,它具有:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
        <execution>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>${main.class.remote-query}</mainClass>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当我使用-X运行mvn时,不会显示执行的实际命令。将Java更改为exec可能会提供它,但是我很好奇在使用Java时是否有办法查看完整的命令行。

java command-line mojo maven exec-maven-plugin

5
推荐指数
1
解决办法
1824
查看次数

将环境变量传递给Maven中的已执行进程

我一直在墙上撞了大约一个小时:我正试图将一个简单的属性(java.library.path)传递给exec-maven-plugin.目标是将其与Netbeans右键单击文件>运行文件过程集成.

所以我把我的POM设置成这样:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1.1</version>
            <configuration>
                <environmentVariables>
                    <java.library.path>native/win32-x86</java.library.path>
                </environmentVariables>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

(我使用旧版本,所以我可以看到执行参数,但它完全可以重现1.2)

然后我右键单击我的文件并单击"运行文件".Netbeans开始这个过程:

 W:\programming\apache-maven-2.2.1\bin\mvn.bat -Dexec.classpathScope=runtime -Dexec.args=-classpath %classpath org.quackedcube.camera.CameraDemo -Dexec.executable=C:\Program Files\Java\jdk1.6.0_21\bin\java.exe -Dnetbeans.execution=true -Dmaven.repo.local=W:\programming\maven-repo process-classes exec:exec
Run Code Online (Sandbox Code Playgroud)

(原始的完整类路径执行已更改为exec:exec希望我的配置已应用)

但我的环境变量显然被忽略了,因为生成的执行程序是:

 Result of cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_21\bin\java.exe" -classpath *snip* org.quackedcube.camera.CameraDemo" execution is: '1'.
Run Code Online (Sandbox Code Playgroud)

我试过了

  • 在enviornmentVariable标记内使用单独的Key和Value标记
  • 直接在enviornmentVariables标记内使用键和值标记(值得一试)
  • 绑定到一个阶段
  • 传递为maven arg并使用exec:java代替
  • 在项目配置页面中将-Djava.library.path = native/win32-x86作为Run参数和VM选项传递

一切都失败了.我真的很茫然.

我想这是在maven中使用JNI的缺点:你必须作为参数传递给测试,运行时,模块运行POM和父POM.

所以我的问题是:如何将java.library.path属性传递给已执行的文件?如果它与Netbeans运行文件功能集成将是很好的(因此我不必更改POM中的类名,构建,然后运行)

java maven-2 netbeans exec-maven-plugin

4
推荐指数
1
解决办法
8805
查看次数

exec-maven-plugin目标在构建期间未启动

你好,

我尝试在maven构建过程中运行main方法.因此,我将exec-maven-plugin和以下代码段添加到我的pom.xml中

<plugin>
     <!-- http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ -->
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>exec-maven-plugin</artifactId>
     <version>1.1.1</version>
     <executions>
      <execution>
       <id>compile-reports</id>
       <phase>compile</phase>
       <goals>
        <goal>java</goal>
       </goals>
       <configuration>
        <mainClass>at.xyz.dls.util.JasperReportCompiler</mainClass>
       </configuration>
      </execution>
     </executions>
    </plugin>
Run Code Online (Sandbox Code Playgroud)

当我从命令行调用它时,主类存在并且也被执行:

mvn exec:java -Dexec.mainClass="at.xyz.dls.util.JasperReportCompiler"
Run Code Online (Sandbox Code Playgroud)

我还尝试创建一个空的新项目进行测试,如果pom中的其他依赖性导致问题,但没有成功.在〜/ .m2文件夹的maven settings.xml中,只有镜像条目,但没有可能导致问题的配置文件或其他任何内容.

它只是没有启动它.当我在org.codehouse下删除我的repo中的所有工件时,它没有下载exec-maven-plugin.只有当我进行命令行调用时.

任何提示?提前致谢!

编辑:我忘了提到我用过"mvn clean install".所以它应该已经通过了编译阶段......

编辑:

到目前为止,我无法解决问题.到目前为止,感谢您的回答!我会再次尝试提供所有信息,希望你们其中一个人找到可疑的部分.我不知道了......

我做了什么:

  • 删除我的maven代理中的文件夹org/codehouse/mojo.只是为了显示,加载依赖项时.
  • 显示一些java和maven版本信息
  • 用以下代码构建项目:mvn -clean install(应该通过测试阶段来执行我的main方法)
  • 执行main方法显示,exec-maven-plugin只在之后加载并运行

据我所知,调用"mvn clean install"应该通过测试阶段(测试执行...),因此应该调用exec-maven-plugin,它应该执行main方法.我对吗?

D:\Eclipse-3.6.1-JSF\ws\exec-test>java -version java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)

D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn -version Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200) Java version: 1.6.0_21 Java home: C:\Programme\Java\jdk1.6.0_21\jre …
Run Code Online (Sandbox Code Playgroud)

maven-2 exec-maven-plugin

4
推荐指数
1
解决办法
1万
查看次数

exec maven 插件:退出代码

我有以下插件来运行.sh脚本:

<plugin>
  <artifactId>exec-maven-plugin</artifactId>
  <groupId>org.codehaus.mojo</groupId>
  <executions>
    <execution>
      <id>deploy-bundles</id>
      <phase>install</phase>
      <goals>
        <goal>exec</goal>
      </goals>
      <configuration>
        <executable>${basedir}/deploy.sh</executable>
        <successCodes>
            <successCode>0</successCode> <-- Not working
        </successCodes>
      </configuration>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

它将一些文件夹和文件复制到某些位置。有用。但是,为了以防万一,我希望有一个失败错误机制。set -e我的.sh脚本中已经有了命令,但我也想要一个 Maven 解决方案。我听说有一个名为的标签successCodes,我尝试合并它。但到目前为止没有运气。有人能指出正确的做法吗?

编辑:我的.sh脚本如下所示:

cp ../template/config.properties $component/conf
cp ../../runtime/group1/group1.mw/conf/log4j.xml $component/conf
# if the component is planning, create an additional folder called plans
if [[ $component == *".planning"* ]] 
then
mkdir -p $component/plans
    # copy all the plans here
    cp ../../mission.planning/plans/* $component/plans
fi  
Run Code Online (Sandbox Code Playgroud)

如果这些文件夹/文件不存在,预计会失败。因此,作为测试,我手动更改了上面的路径并期望它失败。它确实使执行过程失败并告诉我错误(因为我set …

bash maven exec-maven-plugin

4
推荐指数
1
解决办法
6662
查看次数

如何在exec-maven-plugin上设置file.encoding属性?

我试图通过exec-maven-plugin执行我的独立应用程序,但是它以WIN编码而不是UTF-8开始。我读到有关Java命令行键-Dfile.encoding = UTF-8的信息。如何将此属性设置为我的应用程序?谢谢

Maven Pom:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
                <executable>java</executable>
                <mainClass>my.main.Class</mainClass>
            </configuration>                
        </plugin>
Run Code Online (Sandbox Code Playgroud)

utf maven exec-maven-plugin

3
推荐指数
2
解决办法
2439
查看次数

Maven在测试阶段之前运行类:exec-maven-plugin exec:java不执行类

我在Jenkins盒子上运行使用Maven构建的jUnit4测试.我的目标是在执行测试之前恢复测试数据库.

看起来像exec-maven-plugin是要走的路,但是我无法让它运行起来.有什么指针吗?虽然有很多例子,但mojo网站上的文档非常简洁.

我现在需要运行的课程住在:

MyProject.src.test.java._tools.BuildTestEnvironment.java

我的pom.xml包括:

<pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>            
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>build-test-environment</id>
                    <phase>generate-test-resources</phase>            
                    <goals>
                        <goal>java</goal>            
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>src.test.java._tools.BuildTestEnvironment</mainClass>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
Run Code Online (Sandbox Code Playgroud)

在Jenkins运行,没有任何事情发生.如果我在本地运行它,我会

我尝试过的事情没有成功:

  1. 在Jenkins中运行构建:没有任何事情发生.该项目构建并开始运行测试,但我的课程没有运行.

  2. 在本地运行构建:与Jenkins中的结果相同.这并不奇怪.

  3. 在本地运行generate-test-resources:ClassNotFoundException.即:

    mvn exec:java generate-test-resources
    java.lang.ClassNotFoundException:src.test.java._tools.BuildTestEnvironment

  4. 将类编译成jar,然后将其添加到我的pom中.

更新:

在阅读@ ppuskar的评论之后,我尝试了一下我的buildxxx类.将它移动到src.main.java._tools.BuildTestEnvironment后,我仍然收到类似的消息.这是我的构建日志,如果有帮助:

[DEBUG]调用:test.java._tools.BuildTestEnvironment.main()
[DEBUG]插件依赖项将被排除.
[DEBUG]将包括项目依赖项.
[DEBUG]收集的项目工件[joda-time:joda-time:jar:2.3:compile,net.sf.jt400:jt400:jar:6.7:compile,junit:junit:jar:4.11:compile,org.hamcrest:hamcrest -core:jar:1.3:compile,com.fasterxml.jackson.core:jackson-core:jar:2.3.0:compile,com.fasterxml.jackson.core:jackson-databind:jar:2.3.0:compile,com .fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile,org.hamcrest:hamcrest-all:jar:1.3:compile,org.apache.logging.log4j:log4j-api:jar:2.0-rc1 :compile,org.apache.logging.log4j:log4j-core:jar:2.0-rc1:compile]
[DEBUG]收集项目类路径[C:\ workspace\VSP_UnitTest\target\classes]
[DEBUG]添加到classpath:file:/C:/ workspace/VSP_UnitTest/target/classes/
[DEBUG]添加项目依赖项工件:joda-time到classpath
[DEBUG]添加项目依赖项工件:jt400到classpath
[DEBUG]添加项目依赖项工件:junit到classpath
[DEBUG]添加项目依赖项工件:hamcrest-core到classpath
[DEBUG]添加项目依赖项工件:jackson -core to classpath
[DEBUG]添加项目依赖项工件:jackson-databind到classpath
[DEBUG]添加项目依赖项工件:jackson-annotations到classpath
[DEBUG]添加项目依赖项工件:hamcrest-all到classpath
[DEBUG]添加项目依赖项工件:log4j-api到classpath
[DEBUG]添加项目依赖项工件:log4j-core到类路径
[DEBUG]加入线程Thread [test.java._tools.BuildTestEnvironment.main(),5,test.java._tools.BuildTestEnvironment]
[警告] java.lang.ClassNotFoundException:
java.net.URLClassLoader $ 1.run中的test.java._tools.BuildTestEnvironment(URLClassLoader.java:366)
java.net.URLClassLoader $ …

java maven exec-maven-plugin jenkins

3
推荐指数
3
解决办法
5509
查看次数

java maven exec-maven-plugin没有在mvn clean install上执行

后续问题的后续: Maven在测试阶段之前运行类:exec-maven-plugin exec:java不执行类.

我在jenkins盒子上运行jUnit4测试,用maven构建.我需要在构建的测试阶段之前运行特定的main方法java程序.目的是在测试运行之前恢复测试数据库.

如果我运行了这个exec分配给的确切阶段,我的类按预期执行; 但是当我运行整个构建时,我的类不会执行:

具体来说,它运行:
mvn -X exec:java generate-test-resources

但不运行:
mvn -X -e install
- 或 -
mvn -X -e clean install

pom.xml: 我的pom.xml文件包括:

<pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>            
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>build-test-environment</id>
                    <phase>generate-test-resources</phase>          
                    <goals>
                        <goal>java</goal>           
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>main.java._tools.BuildTestEnvironment</mainClass>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
Run Code Online (Sandbox Code Playgroud)

生命周期默认: 我还没有看到maven的生命周期.日志将其报告为:

[DEBUG] Lifecycle default -> [
    validate,
    initialize,
    generate-sources,
    process-sources,
    generate-resources,
    process-resources,
    compile,
    process-classes,
    generate-test-sources,
    process-test-sources,
    generate-test-resources,
    process-test-resources,
    test-compile,
    process-test-classes,
    test,
    prepare-package,
    package, …
Run Code Online (Sandbox Code Playgroud)

java maven exec-maven-plugin jenkins

3
推荐指数
2
解决办法
6557
查看次数

在配置文件中运行插件的目标

    <profile>
        <id>integration-tests</id>
        <activation>
            <property>
                <name>integrations</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.4.0</version>
                    <executions>
                        <execution>
                            <id>script-chmod</id>
                            <phase>integration-test</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>chmod</executable>
                                <arguments>
                                    <argument>+x</argument>
                                    <argument>integration-test-docker/integrations.sh</argument>
                                </arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>script-exec</id>
                            <phase>integration-test</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>integration-test-docker/integrations.sh</executable>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
Run Code Online (Sandbox Code Playgroud)

此配置文件中包含更多内容,但我只包含了我想要运行的内容.如何执行此特定插件的特定目标?

我试过mvn exec:exec但是我明白了

[错误]无法执行目标org.codehaus.mojo:exec-maven-plugin:1.3.2:exec(default-cli)on project ando:目标org.codehaus.mojo的参数'executable':exec-maven-插件:1.3.2:exec丢失或无效 - > [帮助1]

此外,错误输出表明版本1.3.2,但我正在使用1.4.0.

pom.xml maven-3 maven exec-maven-plugin maven-profiles

3
推荐指数
1
解决办法
5157
查看次数

exec-maven-plugin 无法执行 .sh 脚本:权限被拒绝

我有一个 bash 脚本,我希望 Maven 在编译阶段后运行它,因为该脚本应该部署包。这是我尝试在发布模块中使用的插件:

<plugin>
          <artifactId>exec-maven-plugin</artifactId>
          <groupId>org.codehaus.mojo</groupId>
          <executions>
            <execution>
              <id>deploy-bundles</id>
              <phase>install</phase>
              <goals>
                <goal>exec</goal>
              </goals>
              <configuration>
                <executable>${basedir}/deploy.sh</executable>
              </configuration>
            </execution>
          </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

我的deploy.sh路径正确,因此已得到验证。现在,当我这样做时,mvn install出现以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (deploy-bundles) on project module.release: Command execution failed. Cannot run program "/bla/bla/module.release/deploy.sh" (in directory "/bla/bla/module.release"): error=13, Permission denied -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

首先,我认为这与我编写的 bash 脚本有关。所以我把它改成了一个简单的 bash 脚本,如下所示:

#!/bin/bash          
STR="Hello World!"
echo $STR    
Run Code Online (Sandbox Code Playgroud)

但是,我遇到了同样的错误。所以这与代码无关。我应该给予maven特殊的权利吗?应该使用sudo命令吗?

bash maven exec-maven-plugin

3
推荐指数
1
解决办法
7476
查看次数

将工作目录传递给exec-maven-plugin中的npm

我试图运行npm作为我的maven构建的一部分.我正在使用exec-maven-plugin,这是我在pom.xml中的插件部分

<plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <executions>
                <execution>
                  <id>exec-npm-install</id>
                  <phase>generate-sources</phase>

                  <goals>
                    <goal>exec</goal>
                  </goals>

                  <configuration>
                    <executable>npm</executable>
                    <arguments>
                      <argument>build</argument>
                    </arguments>
                    <workingDirectory>${basedir}/src/main/webapp</workingDirectory>
                  </configuration>

                </execution>
           </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

但是,当我运行mvn clean package或者mvn generate-sources npm时,它没有运行.

在我的package.json中,我有以下脚本.

"scripts": {
    "start": "npm run build && serve .",
    "build": "npm run build-js && npm run build-css",
    "watch": "npm run watch-js & npm run watch-css & serve .",
    "watch-build": "npm run watch-js && npm run watch-css && npm run build-js && npm run build-css && serve .",
    "test": "npm run lint -s && …
Run Code Online (Sandbox Code Playgroud)

maven exec-maven-plugin npm

2
推荐指数
1
解决办法
9314
查看次数