繁体   English   中英

Maven exec插件 - 执行python脚本

[英]Maven exec plugin - Executing a python script

我在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平台工作?

。:-编辑-:。

工作代码SNIPPET

<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>

在Windows中,脚本不可执行。 可执行文件是python解释器,脚本是它的参数,因此将<executable>path to your python interpreter</executable>并将脚本添加为<argument> 我希望同样适用于任何平台,但我不是Python专家。

只是想在较新版本的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM