javafatjar,带有testng的资源和依赖项

kcwpcxri  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(298)

我正在尝试构建一个testngfatjar,但是看起来这个配置并没有添加来自javamain和tests的资源

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <argLine>--enable-preview</argLine>
                <descriptor>src/main/assembly/assembly.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>

下面是config assembly.xml

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>fat-tests</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <unpack>true</unpack>
        <scope>test</scope>
    </dependencySet>
</dependencySets>
<fileSets>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.class</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.xml</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
</fileSets>

我尝试了不同的目标和配置,但找不到如何将所有文件夹添加到jar、java资源和test文件夹。

voase2hg

voase2hg1#

要从target/classes和target/test classes文件夹复制所有资源,请尝试下面的文件。所有资源都将被复制到jar文件的根文件夹中。

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>fat-tests</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <unpack>true</unpack>
        <scope>test</scope>
    </dependencySet>
</dependencySets>
<fileSets>
<fileSet>
        <directory>${project.build.directory}/classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.*</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.class</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.*</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
</fileSets>

相关问题