编辑2:我发现问题了。快速的回答是,我新配置的执行缺少<id>
是导致问题的原因。我把这个问题留在这里,以防对别人有帮助。
我有一个生成一些jUnit源文件的ruby脚本。
我试图使用exec-maven-plugin在默认生命周期的生成源阶段调用这个ruby脚本。以下是我在POM中添加的内容:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>ruby</executable>
<workingDirectory>supporting_files/ruby</workingDirectory>
<arguments>
<argument>CreateUnitTests.rb</argument>
</arguments>
</configuration>
</plugin>
当我在netbeans (clean install
)中做"清洁和构建主项目"时,这似乎正在工作,但是当我运行项目(process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec
与属性:)
exec.classpathScope=runtime
exec.args=-enableassertions -classpath %classpath org.example.MyProject.App
exec.executable=java
运行失败,因为它试图使用(正如我在POM中告诉它的那样)。ruby
作为执行器。可执行
那么,我如何临时使用在生成-测试-源阶段调用脚本的"适当"方式是什么?ruby
(在运行jUnit测试之前运行ruby supporting_files/ruby/CreateUnitTests.rb
),但否则使用java
?
edit:问题似乎不仅仅是改变正在调用的可执行文件…
我写了一个快速的java程序,它只是调用ruby解释器,传递它作为命令行参数接收到的(ruby文件名):
import java.io.IOException;
public class RunRuby {
public static void main(String args[]) throws IOException {
Runtime run = Runtime.getRuntime();
run.exec("ruby "+args[0]);
}
}
允许我避免更改POM中的可执行文件:
<plugin>
<!-- use ruby to generate some jUnit tests -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>generate-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<workingDirectory>supporting_files/ruby</workingDirectory>
<arguments>
<argument>RunRuby</argument>
<argument>CreateUnitTests.rb</argument>
</arguments>
</configuration>
</plugin>
丑,我知道。但无论如何,清理/构建仍然像预期的那样工作,但"运行"仍然失败!下面是错误信息:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1.1:exec (default-cli) on project MyProject: Result of cmd.exe /X /C "java -enableassertions -classpath C:DropboxdevjavaMyProjecttargetclasses;C:Usersusername.m2repositoryLOTSOFJARS org.example.MyProject.App" execution is: '-1'. -> [Help 1]
所以,它回到运行java
,但仍然失败。我注意到的一件奇怪的事情是,它正在执行目标org.codehaus.mojo:exec-maven-plugin:1.1.1:exec
,即使在POM中我告诉它使用1.2
版本…
缺少<id>
导致我的自定义执行成为默认值。修复方法如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<!-- use ruby to generate some jUnit tests during generate-test-sources -->
<id>generate-test-sources</id>
<configuration>
<executable>ruby</executable>
<workingDirectory>supporting_files/ruby</workingDirectory>
<arguments>
<argument>CreateUnitTests.rb</argument>
</arguments>
</configuration>
<phase>generate-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>