我在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>
我在构建项目时遇到以下错误。
Embedded error: Cannot run program "pathToScript/create.py" CreateProcess error=193, %1 is not a valid Win32 application
我安装了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>
答案 0 :(得分:16)
在Windows中,脚本不可执行。可执行文件是python解释器,脚本是它的参数,所以放<executable>path to your python interpreter</executable>
并将脚本添加为<argument>
。我希望同样适用于任何平台,但我不是Python专家。
答案 1 :(得分:0)
只是想在较新版本的exec-maven-plugin中添加它,配置标记必须放在执行标记之后才能工作。
与上面的工作代码段一样:
<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>