[英]Maven exec plugin - Executing a python script
I am using maven on Win 7 to build an application. 我在Win 7上使用maven来构建应用程序。 I use the exec plugin to invoke a python script. 我使用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>
I get the below error when I build the project. 我在构建项目时遇到以下错误。
Embedded error: Cannot run program "pathToScript/create.py" CreateProcess error=193, %1 is not a valid Win32 application
I do have python installed and added to the %PATH variable. 我确实安装了python并添加到%PATH变量中。
How do I fix it such that it will work independent of OS platform ? 如何修复它以使其独立于OS平台工作?
.:-EDIT-:. 。:-编辑-:。
<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>
In Windows, the script isn't executable. 在Windows中,脚本不可执行。 The executable is the python interpreter, and the script is an argument to it, so put <executable>path to your python interpreter</executable>
and add the script as an <argument>
. 可执行文件是python解释器,脚本是它的参数,因此将<executable>path to your python interpreter</executable>
并将脚本添加为<argument>
。 I expect the same should work for any platform, but I'm no Python expert. 我希望同样适用于任何平台,但我不是Python专家。
Just wanted to add that with the newer version of exec-maven-plugin, the configuration tag must be placed after the executions tag to work. 只是想在较新版本的exec-maven-plugin中添加它,配置标记必须放在执行标记之后才能工作。
As in the working snippet above: 与上面的工作代码段一样:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>python-build</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>python</executable>
<workingDirectory>src/main/upgrade/</workingDirectory>
<arguments>
<argument>createChangeSet.py</argument>
</arguments>
</configuration>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.