Rob*_*ram 6 maven-plugin maven
我的pom.xml中有以下内容:
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.myorg.MyClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
该类com.myorg.MyClass位于我的测试源目录中,我可以使用以下命令运行它:
mvn -e exec:java -Dexec.classpathScope="test"
Run Code Online (Sandbox Code Playgroud)
我想要:
-Dexec.classpathScope="test",但我无法弄清楚如何配置该插件在测试类路径中查找.exec:java.有没有办法标记这个插件,以便我通过该标签调用它,而不是只是说"运行在exec:java中的任何东西"?-javaagent房产.我在我的pom.xml中定义了这个属性,测试用例正在使用它.我的"自定义"插件会选择这些属性还是我需要做任何事情来吸引他们?这是属性,直接在其下定义<project>.
<properties>
<spring.version>3.2.6.RELEASE</spring.version>
<atomikos.version>3.9.2</atomikos.version>
<loadTimeWeaverArgLine>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</loadTimeWeaverArgLine>
</properties>
Run Code Online (Sandbox Code Playgroud)
继@ Michal的建议(/sf/answers/2158787711/)之后,这就是我的尝试:
<profile>
<id>run-importer</id>
<properties>
<loadTimeWeaverArgLine>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</loadTimeWeaverArgLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<!--
None of these three options work.
<commandlineArgs>-javaagent:C:/Users/robbram/.m2/repository/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar</commandlineArgs>
<commandlineArgs>${loadTimeWeaverArgLine}</commandlineArgs>
<commandlineArgs>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</commandlineArgs>
<argLine>${loadTimeWeaverArgLine}</argLine>
-->
<classpathScope>test</classpathScope>
<mainClass>com.myorg.MyClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
我运行它:
mvn -e exec:java -Prun-importer
Run Code Online (Sandbox Code Playgroud)
我使用以下任一选项获得以下异常:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project TOLTAT-Model: An exception occured while executing the Java class. null: InvocationTargetException: Error creating bean with name 'loadTimeWeaver' defined in class org.springframework.context.annotation.LoadTimeWeavingConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.instrument.classloading.LoadTimeWeaver org.springframework.context.annotation.LoadTimeWeavingConfiguration.loadTimeWeaver()] threw exception; nested exception is java.lang.IllegalStateException: ClassLoader [java.net.URLClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar -> [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 TOLTAT-Model: An exception occured while executing the Java class. null
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
Run Code Online (Sandbox Code Playgroud)
我可以确认com.myorg.MyClass正在执行主类.我可以看到它的其他输出.我也可以确认loadTimeWeaverArgLine这个POM的其他部分有用.它已成功用于集成测试:
<profile>
<id>integration-tests</id>
<build>
<plugins>
<!-- Integration tests require additional loadtime Spring argument -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<forkMode>once</forkMode>
<argLine> ${loadTimeWeaverArgLine}</argLine>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
Upodate(2015年6月17日星期三,下午12:11:17):根据Michal的最新评论,我现在按照我的意愿工作:
<profile>
<id>run-importer</id>
<properties>
<loadTimeWeaverArg>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</loadTimeWeaverArg>
<log4JConfigArg>-Dlog4j.configuration=file:${project.build.directory}/path/to/log4j.properties</log4JConfigArg>
<mainClassArg>com.myorg.MyClass</mainClassArg>
<arg1>foo</arg1>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>${log4JConfigArg}</argument>
<argument>${loadTimeWeaverArg}</argument>
<argument>-classpath</argument>
<classpath />
<argument>${mainClassArg}</argument>
<argument>${arg1}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
我运行它:
mvn -e exec:exec -Prun-importer
Run Code Online (Sandbox Code Playgroud)
这种方法的优点:
mvn -e exec:exec.-Darg1="bar"我不确定你实际上要通过这个完成什么,因为它对 Maven 的使用相当不自然。然而,所有这些东西在技术上都是可行的:
1/
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.myorg.MyClass</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
2/
您可以使用配置文件,并将不同的插件配置放在不同的配置文件中。然后你打电话:
mvn -e exec:java -Pmy-first-profile
Run Code Online (Sandbox Code Playgroud)
不过我觉得这真的很奇怪。我的建议是重新考虑您的案例,也许选择另一种方法或工具。
3/
经过作者编辑后问题本身的最终解决方案。
| 归档时间: |
|
| 查看次数: |
4288 次 |
| 最近记录: |