Java 作为Maven构建过程的一部分,如何调用ruby脚本?
编辑2:我发现了问题。快速的答案是,我新配置的执行缺少Java 作为Maven构建过程的一部分,如何调用ruby脚本?,java,unit-testing,build-process,maven-3,exec-maven-plugin,Java,Unit Testing,Build Process,Maven 3,Exec Maven Plugin,编辑2:我发现了问题。快速的答案是,我新配置的执行缺少,这就是问题的原因。我将问题留在这里,以防对其他人有所帮助。 我有一个ruby脚本,它生成了一些jUnit源文件 我试图在的GenerateSources阶段使用调用这个ruby脚本。为了实现这一目标,我在POM中添加了以下内容: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-
,这就是问题的原因。我将问题留在这里,以防对其他人有所帮助。
我有一个ruby脚本,它生成了一些jUnit源文件
我试图在的GenerateSources阶段使用调用这个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>
运行失败,因为它试图使用ruby
作为exec.execute(正如我在POM中告诉它的那样)
那么,我如何临时使用ruby
(在运行jUnit测试之前运行ruby-supporting\u-files/ruby/CreateUnitTests.rb
),而不是使用java
?在生成测试源阶段,调用脚本的“正确”方式是什么
编辑:问题似乎不仅仅是更改调用哪个可执行文件…
我编写了一个快速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>
因此,它又回到了运行java
,但仍然失败。我注意到的一件奇怪的事情是,它正在执行目标org.codehaus.mojo:exec maven plugin:1.1.1:exec
,尽管在POM中我告诉它使用版本1.2
。缺少
导致我的自定义执行成为默认执行。以下是修复方法:
<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>
org.codehaus.mojo
execmaven插件
1.2
生成测试源
红宝石
支持\u文件/ruby
CreateUnitTests.rb
生成测试源
执行官
问题似乎不仅仅是exec.execute,我将编辑我的问题..谢谢Drews,对我来说很好!我想要一些东西作为构建的一部分来运行我的rspec测试,如果它们不运行,就会失败。
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:\Dropbox\dev\java\MyProject\target\classes;C:\Users\username\.m2\repository\LOTS\OF\JARS org.example.MyProject.App" execution is: '-1'. -> [Help 1]
<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>