要在项目jar中添加testoutputdirectory文件。使用下面的方法尝试过,但是测试类未包含在罐子中
需要进行哪些更改才能在项目jar中包含相同内容?
在下面的pom.xml中使用
<build>
<finalName>${project.name}</finalName>
<testOutputDirectory>test/classes</testOutputDirectory>
<resources>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${final.name}</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptor>./src/main/resources/assembly/assembly.xml</descriptor>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
.........
</build>
下面我在assembly.xml中
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<moduleSets>
<moduleSet>
<sources>
<fileSets>
<fileSet>
<directory>.</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>test/classes/**/*.class</include>
</includes>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
</assembly>
答案 0 :(得分:1)
我不认为这样做是个好主意。也许考虑创建一个单独的测试罐。您可以使用maven-jar-plugin test-jar goal
尽管如此,如果您确实想这样做,可以通过设置
taskmanager.network.bind-policy
喜欢:
testOutputDirectory
然后将Tests.java编译为目标/类,然后从那里将maven-jar-plugin打包到jar中。
答案 1 :(得分:0)
谢谢大家的帮助。
我可以使用以下内容将testoutput目录包含到jar中。
<build>
<finalName>${project.name}</finalName>
<testOutputDirectory>test/classes</testOutputDirectory>
<resources>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${final.name}</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/assembly/assembly.xml</descriptor>
</descriptors>
<!-- descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs-->
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
.......
</plugins>
..........
</build>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>jar-with-dependencies</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>./target/classes/</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/*.class</include>
</includes>
</fileSet>
<fileSet>
<directory>.</directory>
<outputDirectory></outputDirectory>
<includes>
<include>test/classes/**/*.class</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>