SFD*_*SFD 6 java javaagents maven
我有一个简单的 java 项目,其中包含具有当前架构的 Junit 测试用例:
pom.xml
src/main/java/com/Example.Java
src/test/java/com/ExampleTest.java
Run Code Online (Sandbox Code Playgroud)
pom.xml的内容如下:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>SampleExample</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
为了执行测试,我只需从 bash 调用mvn test即可。正如预期的那样,这将运行测试。现在回答我的问题:
在 maven 之外指定javagent只需通过-javaagen t 选项即可完成。如何在 Maven 框架内执行此操作,以便在执行 mvn test 时加载我指定的代理?(即如何添加 Maven 在执行测试时传递给“java”命令的自定义参数)
在 POM 中定义 Surefire 插件并通过 Surefire 的配置传递 JVM 参数。
例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>-javaagent:/path/to/javaagent</argLine>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
背景信息:目标默认test
绑定(有关默认绑定的更多详细信息请参见此处),因此您可能已经在运行 Surefire 插件而没有意识到。现在唯一的变化是您需要更改 Surefire 插件的配置,这要求您按照我上面显示的示例将其显式包含在 POM 中。如果不使用 Surefire 插件,则无法运行目标,并且如果不配置 Surefire 插件,则无法告诉 Surefire 使用 JVM 参数。surefire:test
test
归档时间: |
|
查看次数: |
5566 次 |
最近记录: |