gpt4 book ai didi

python - exec-maven-plugin 无法在编译阶段之前启动

转载 作者:太空宇宙 更新时间:2023-11-04 10:51:24 25 4
gpt4 key购买 nike

我想将附加文本写入 Java 资源文件(将两个 .java 文件合并为一个)。我写了一个 python 脚本来这样做。

我还想使用 Maven 自动执行这些步骤(合并文件、编译、打包)。我是 Maven 的新手,我发现 exec-maven-plugin可以运行python脚本。

我尝试设置 <phase>process-resources</phase>试图让它在编译前启动,但 Eclipse 提示 Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
(execution: default, phase: process-resources)

下面是我的 exec-maven-plugin 的 pom:

  <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-resources</phase> <!-- Eclipse complains an error here -->
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>python</executable>
<workingDirectory>src/main/python</workingDirectory>
<arguments>
<argument>combine.py</argument>
</arguments>
</configuration>
</plugin>

有人知道我怎样才能实现这个目的吗?非常感谢。

最佳答案

这是 Eclipse M2e 插件技巧。 Sachin Shekhar R是的,但是对于像我这样的新手来说答案还不够明确。这是我的理解:

参见 http://wiki.eclipse.org/M2E_plugin_execution_not_covered .
在 Eclipse M2e 中有两种方法可以做到这一点。

  1. 使用 Sachin Shekhar R 中列出的代码的回答。请注意,这段代码必须在 <pluginManagement><plugins> 下和 <pluginManagement>必须在里面 <plugins> .示例代码:

    <build>
    <plugins>
    <plugin>
    <!-- plugins here-->
    </plugin>
    </plugins>
    <pluginManagement>
    <plugins>
    <plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
    <lifecycleMappingMetadata>
    <pluginExecutions>
    <pluginExecution>
    <pluginExecutionFilter>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <versionRange>[1.2.1,)</versionRange>
    <goals>
    <goal>exec</goal>
    </goals>
    </pluginExecutionFilter>
    <action>
    <ignore/>
    </action>
    </pluginExecution>
    </pluginExecutions>
    </lifecycleMappingMetadata>
    </configuration>
    </plugin>
    </plugins>
    </pluginManagement>
    </build>

    这只适用于项目。

  2. 使用 Eclipse M2e 插件的“快速修复”功能。它存在于 1.0 版本之后。在 Problems 中查找错误标签。右键单击它,选择“快速修复”。将弹出一个快速修复窗口,选择第二个选项 Mark goal exec as ignored in Eclipse build in Eclipse references (experimental) .
    此方法将在 <lifecycleMappingMetadata> 之间编写上面的代码进入生命周期映射的工作区配置文件进入 workspace/.metadata/.plugins/org.eclipse.m2e.core/lifecycle-mapping-metadata.xml
    这适用于整个工作区

关于python - exec-maven-plugin 无法在编译阶段之前启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13604255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com