我在Win 7上使用maven来构建应用程序.我使用exec插件来调用python脚本.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>create-dir</id>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>src/main/upgrade/create.py</executable>
<arguments>
<argument>ChangeSet.txt</argument>
</arguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我在构建项目时遇到以下错误.
Embedded error: Cannot run program "pathToScript/create.py" CreateProcess error=193, %1 is not a valid Win32 application
Run Code Online (Sandbox Code Playgroud)
我确实安装了python并添加到%PATH变量中.
如何修复它以使其独立于OS平台工作?
.:-编辑-:.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<executable>python</executable>
<workingDirectory>src/main/upgrade/</workingDirectory>
<arguments>
<argument>createChangeSet.py</argument>
</arguments>
</configuration>
<id>python-build</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我有一个项目配置为使用Maven构建和运行.该项目依赖于特定于平台的本机库,我使用此处的策略来管理这些依赖项.
本质上,特定平台的.dll
或.so
文件被打包到jar中,并通过标识目标平台的分类器推送到Maven服务器.然后,maven-dependency-plugin解包特定于平台的jar,并将本机库复制到目标文件夹.
通常我会mvn exec:java
用来运行Java程序,但是exec:java
在与Maven相同的JVM中运行应用程序,这会阻止我修改类路径.由于必须将本机依赖项添加到类路径中,因此我不得不使用mvn exec:exec
.这是pom的相关片段:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Djava.library.path=target/lib</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.example.app.MainClass</argument>
</arguments>
</configuration>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)
这适用于应用程序的默认配置,但我希望能够在命令行中指定一些可选参数.理想情况下,我想做这样的事情:
mvn exec:exec -Dexec.args="-a <an argument> -b <another argument>"
Run Code Online (Sandbox Code Playgroud)
不幸的是,指定exec.args
变量会覆盖我在pom中的参数(这些参数是设置类路径并运行应用程序所必需的).有没有解决的办法?在命令行中指定一些可选参数而不覆盖我在pom中的内容的最佳方法是什么?
执行mvn exec:java
时无法正确解析配置参数,抛出以下错误:
[错误]无法执行目标org.codehaus.mojo:exec-maven-plugin:1.2.1:项目自动测试程序中的java(default-cli):无法解析mojo的配置org.codehaus.mojo:exec-maven -plugin:1.2.1:java:无法将配置值分配给java.lang.String类型的数组:[ - classpath,Classpath {}, - glue,com.company.test.cucumber, - format,pretty, - -format,html:C:\ workspace\autotest\target] - > [帮助1]
这是使用的插件配置(使用Apache Maven 3.0.3):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</executableDependency>
<mainClass>cucumber.cli.Main</mainClass>
<commandlineArgs>-Dfile.encoding=UTF-8</commandlineArgs>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>--glue</argument>
<argument>com.company.test.cucumber</argument>
<argument>--format</argument>
<argument>pretty</argument>
<argument>--format</argument>
<argument>html:${project.basedir}\target</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我有一个使用 exec-maven-plugin 执行带有三个参数的 shell 脚本的 pom。运行时mvn clean install -X -e
,它在该步骤失败并出现错误,
[DEBUG] Toolchains are ignored, 'executable' parameter is set to C:\dev\intellij\projects\project-in-question\driver/src/main/scripts/dependencies.sh
[DEBUG] Executing command line: [C:\dev\intellij\projects\project-in-question\driver\src\main\scripts\dependencies.sh, C:\dev\intellij\projects\project-in-question\driver\target/project-in-question.dependencies, C:\dev\intellij\projects\project-in-question\driver\target, third-parameter]
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (dependencies) on project project-in-question: Command execution failed.: Cannot run program "C:\dev\intellij\projects\project-in-question\driver\src\main\scripts\dependencies.sh" (in directory "C:\dev\intellij\projects\project-in-question\driver"): CreateProcess error=193, %1 is not a valid Win32 application -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (dependencies) on project project-in-question: Command execution failed.
Run Code Online (Sandbox Code Playgroud)
pom.xml 的相关部分:
...
<plugin>
<groupId>org.codehaus.mojo</groupId> …
Run Code Online (Sandbox Code Playgroud) 三周前,我完成了一个 Web 应用程序的工作。一切都运行没有问题。
现在,三周后,什么都没有改变(!!!),我想再次运行该应用程序,但这次我收到以下错误消息:
An error occurred while parsing the server response. Error message is: Provider org.glassfish.json.JsonProviderImpl not found
Exception in thread "main" com.michael.optimizer.exceptions.JsonException: This is a general JSON error. Check logs for details.)
at com.michael.optimizer.api.JsonRequest.doJsonRequest(JsonRequest.java:36)
at com.michael.optimizer.api.StationApi.doJsonRequest(StationApi.java:150)
at com.michael.optimizer.api.StationApi.areaSearch(StationApi.java:73)
at com.michael.optimizer.Optimizer.main(Optimizer.java:23)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at …
Run Code Online (Sandbox Code Playgroud) 是否可以使用带-e开关的exec-maven-plugin执行exec目标?我得到了一个MojoExecutionException
.
从文档:
exec:exec
在单独的进程中执行程序和Java程序.exec:java
在同一个VM中执行Java程序.我想分叉一个java程序.我已经有了它的工作exec:java
但是没有分叉.所以明显的举措是将目标改为exec
.问题是,语法与语法exec
完全不同java
.它没有像includeProjectDependencies
,includePluginDependencies
等等的标签.是否有一个我可以使用的插件,就像它的叉子一样,它有一个方便的语法,比如#2?IMO,#2应该只有一个<fork>true</fork>
配置.
我想使用exec-maven-plugin来获取git'revision',所以我使用以下配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>gitVersion</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>git</executable>
<workingDirectory>./</workingDirectory>
<arguments>
<argument>rev-list</argument>
<argument>master</argument>
<argument>--count</argument>
</arguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但我遇到了一个问题 - 如何将输出分配给其他插件/ livecycles中的任何变量?
(我能够使用gmaven-plugin和执行groovy脚本完成它,但我发现它有点矫枉过正/不那么优雅)
编辑:供参考,groovy工作解决方案:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>2.0</providerSelection>
<properties>
<script>git rev-list master --count</script>
</properties>
<source>
def command = project.properties.script
def process = command.execute()
process.waitFor()
def describe = process.in.text.trim()
println "setting revision to: " + describe
project.properties.setProperty('gitVersion',describe)
</source>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 所以当我尝试执行Maven exec插件时,我在Bamboo计划之一中遇到了这个恼人的异常:Unbalanced quotes "-Dargument=value
.
我正在尝试运行的命令是:
mvn exec:exec -Dexec.args="-Dargument=value"
Run Code Online (Sandbox Code Playgroud)
当我在命令行中执行它时,同样的命令工作得很好.有任何想法吗?
在我的项目中,我们创建了一个Maven模块来获取特定的JBoss AS并解压缩.
然后,所有测试用例都可以作为嵌入式容器在此Jboss AS下运行.
我们使用jboss-ejb3-embedded-standalone来调用嵌入式容器,但是,它只是从环境变量中找到JBOSS_HOME并使用它来运行.因此,我们必须每mvn安装更新JBOSS_HOME.
我试着在maven中通过引入exec-maven-plugin来做到这一点,如下所示:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>env</executable>
<environmentVariables>
<JBOSS_HOME>
C:/Sample/embedded-container/jboss-${version.org.jboss.jbossas}
</JBOSS_HOME>
</environmentVariables>
</configuration>
<executions>
<execution>
<id>resetJbossHome</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在控制台的输出中,我可以看到
[INFO] --- exec-maven-plugin:1.2.1:exec (resetJbossHome) @ test-embedded ---
....
JBOSS_HOME=C:/Sample/embedded-container/jboss-6.1.0.Final
Run Code Online (Sandbox Code Playgroud)
....
但是在启动JBOSS时,它仍在运行JBOSS_HOME设置源的JBOSS.
此外,我也试过使用maven-antrun-plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copyRelease</id>
<phase>pre-integration-test</phase>
<configuration>
<tasks>
<exec executable="env">
<env key="JBOSS_HOME" value="C:/Sample/embedded-container/jboss-${version.org.jboss.jbossas}"/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
事实证明是一样的.
我配置错了还是有更好的方法?