我继承了一个代码库:)
在src/test/java /下面有一个我需要运行的文件(我需要运行它public static void main(String[] args)
,而不是其中的@Test
方法).
我最接近的是:
mvn -e exec:java -Dexec.mainClass="com.me.packagex.RunFile" -Dexec.classpathScope="test"
Run Code Online (Sandbox Code Playgroud)
但那失败了,似乎是因为RunFile想要使用src/main/java/com/me/packagex /(notice,/ main /,not/test /)下的类.其下的文件与RunFile在同一个包中,即'package com.me.packagex;'.
如果我删除它-Dexec.classpathScope="test"
然后它根本找不到RunFile.就好像我需要给它两个范围,但它不接受"测试,编译".
我从(亲爱的离开)继承的人曾经从Eclipse运行它.我需要一种从命令行运行它的方法.
我希望这清楚地解释了.
tyvm,
这很有希望.帕斯卡,我已经试过你的榜样,并且没有为我工作.
虽然现在我看着它 - 它没有找到Demo,而不是找到Dog.
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.6.0_18
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-25-generic" arch: "i386" Family: "unix"
$ mvn -e exec:java -Dexec.mainClass="com.stackoverflow.Demo" -Dexec.classpathScope="test"
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. …
Run Code Online (Sandbox Code Playgroud) 我试图运行exec-maven-plugin
的exec:java
一个简单的两模块项目的目标,其中一个模块依赖于其他.到目前为止,我找不到有效的配置.这是一个简化的测试用例:
这是父母pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mkscrg.sandbox</groupId>
<artifactId>exec-multi-module-test</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
module1
的pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>exec-multi-module-test</artifactId>
<groupId>com.mkscrg.sandbox</groupId>
<version>1.0</version>
</parent>
<artifactId>module1</artifactId>
</project>
Run Code Online (Sandbox Code Playgroud)
module2
的pom:http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<parent>
<artifactId>exec-multi-module-test</artifactId>
<groupId>com.mkscrg.sandbox</groupId>
<version>1.0</version>
</parent>
<artifactId>module2</artifactId> …
Run Code Online (Sandbox Code Playgroud) 我想运行一个应该在maven包阶段开始的守护程序线程.这是我在pom.xml中的内容:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.test.Startup</mainClass>
<cleanupDaemonThreads>true</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
以下是Startup类的内容:
public class Startup {
public static class Testing extends Thread {
@Override
public void run() {
while(true) {
System.out.println("testing..");
}
}
}
public static void main(String[] list) throws Exception {
Testing t = new Testing();
t.setDaemon(true);
t.start();
}
}
Run Code Online (Sandbox Code Playgroud)
线程开始运行但编译在线程运行时停止.经过一段时间(超时或其他)后,线程停止并继续编译.无论如何,我可以让这个线程在后台开始,并使编译继续自己?
maven的一些输出:
[WARNING] thread Thread[Thread-1,5,com.test.Startup] was interrupted but is still alive after waiting at least 15000msecs
[WARNING] thread …
Run Code Online (Sandbox Code Playgroud) 我正在研究Smooks - Camel Integration.我遇到了错误.当我尝试使用mvn exec运行它时,Build失败了:java
[错误]: 无法在项目上执行目标org.codehaus.mojo:exec-maven-plugin:1.2:java(default-cli) camel-example-smooks-integration:
我的控制台日志如下:
[ERROR] For more information about the errors and possible solutions, please read the following
articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException
C:\apache-camel-2.11.0\examples\camel-example-smooks-integration>mvn exec:java
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for
org.apache.camel:camel-example-smooks-integration:bundle:2.11.0
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate
declaration of plugin org.codehaus.mojo:exec-maven-plugin @ line 138, column 9
[WARNING]
[WARNING] It is highly recommended to fix these problems …
Run Code Online (Sandbox Code Playgroud) 我的Java EE proj构建正常,但在尝试执行时会出现以下错误:
gert@gert-VirtualBox:~/workspace/CDBOOKSTORE$ mvn exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building CDBOOKSTORE 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.8:copy (default) @ CDBOOKSTORE ---
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.505s [INFO] Finished at: Fri Nov 08 14:01:40 EST 2013
[INFO] Final Memory: 9M/21M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行TestNG测试.我的项目组织是--src-> test-> java-> com-> shn-> library以下命令在Windows中运行良好但在Linux中运行失败.
mvn -X clean exec:java -Dexec.mainClass="com.shn.library.RunSuitesInParallel" -Dexec.classpathScope=test -e
Run Code Online (Sandbox Code Playgroud)
在运行相同命令的Linux中看到错误 -
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project UAF: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project UAF: An exception occured while executing the Java class. com.shn.library.RunSuitesInParallel
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) …
Run Code Online (Sandbox Code Playgroud) 我需要在Linux和MS-Windows平台上运行外部脚本.
exec-maven-plugin
吗?我应该输入什么文件名<executable>....</executable>
?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>compile-jni</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./compile-jni</executable>
<workingDirectory>${basedir}/src/main/cpp</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)我在Makefile
Linux/MS-Windows这两个平台上使用相同的功能
我的剧本compile-jni.bat
:
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
bash -c "make"
Run Code Online (Sandbox Code Playgroud)
我的剧本compile-jni.sh
:
#!/bin/sh
make
Run Code Online (Sandbox Code Playgroud)
两位同事提出了替代方案:
使用一个变量script.extension
的变化<executable>./compile-jni${script.extension}</executable>
中pom.xml
,并在命令行中添加变量mvn compile -Dscript.extention=.bat
或者在调用maven之前设置Visual Studio环境变量:
call "C:\%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
mvn compile #(the same script 'bash -c "make"' works on both platforms)
Run Code Online (Sandbox Code Playgroud)但在这两种解决方案中,Eclipse用户可能会被卡住......我仍然在寻找一种自动而优雅的解决方案......
我正在尝试在自定义容器的顶部执行我的应用程序部署的集成品尝.由于我的容器是自定义的,我不能使用Maven Cargo插件来设置容器.
我的容器:
我的问题是我必须在不同的进程中运行我的容器,因为它需要在我的测试执行时继续运行.此外,我的测试中有一个API,让我等待容器准备就绪(一种带超时的查找).
我已将以下行添加到我的pom.xml中
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>scripts/start-agent.bat</executable>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这将调用一个仅包含的脚本
开始调用gs-agent.bat
然而,mvn exec插件被卡住了,我的测试没有运行.根据我如何从Java应用程序运行批处理文件中的建议?,我已经修改了我的pom.xml如下:
<configuration>
<executable>cmd</executable>
<arguments>
<argument>/C</argument>
<argument>start</argument>
<argument>gs-agent.bat</argument>
</arguments>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但这似乎没有解决问题:
我想使用exec:java插件从命令行调用主类.我可以从命令行传递参数-Dexec.args="arg0 arg1 arg2"
,我不知道如何传递系统属性.我试过'-Dexec.systemProperties ="key = value"`但没有效果.
pom.xml
看起来像这样:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>ibis.structure.Structure</mainClass>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用maven执行以下方案:
这是pom.xml snip:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>launch-myApp</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-DMY_APP_HOME=/usr/home/target/local</argument>
<argument>-Djava.library.path=/usr/home/other/lib</argument>
<argument>-classpath</argument>
<classpath/>
<argument>com.foo.MyApp</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
如果我执行mvn post-integration-test,我的应用程序将作为maven进程的子进程启动,但是应用程序进程阻止maven进程执行下一阶段的集成测试.后来我发现maven exec插件中存在一个错误(或缺少功能?),因为应用程序进程阻止了maven进程.为了解决这个问题,我在一个shell脚本中封装了MyApp.java的调用,然后附加了"/ dev/null 2>&1&"以产生一个单独的后台进程.这是来自runTest.sh的剪辑(这只是一个剪辑,而不是实际剪辑):
java - DMY_APP_HOME =$2 com.foo.MyApp > /dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)
虽然这解决了我的问题,还有其他办法吗?我错过了exec-maven-plugin的任何论据吗?
maven ×7
java ×4
maven-2 ×2
batch-file ×1
integration ×1
java-ee ×1
jboss ×1
maven-3 ×1
maven-plugin ×1
pom.xml ×1
shell ×1
smooks ×1