如何为多模块maven项目构建可执行jar

时间:2017-11-09 04:46:00

标签: maven

我有一个父maven项目SampleProject,它有两个模块Sample1和Sample2。 SampleProject有一个main方法,如何为SampleProject创建一个可执行jar,以便它执行main方法

SampleProject的Pom.xml是: http://maven.apache.org/xsd/maven-4.0.0.xsd">     4.0.0

<groupId>com.test.sample</groupId>
<artifactId>SampleProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>SampleProject</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.0.7</version>
    </dependency>
    <dependency>
        <groupId>sample</groupId>
        <artifactId>com.sample</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>C:\\Users\\pchand\\Desktop\\ExtentReport-0.0.1-SNAPSHOT.jar</systemPath>
    </dependency>
</dependencies>
<modules>
    <module>Sample1</module>
    <module>Sample2</module>
</modules>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.test.sample.SampleProject.Runner</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

0 个答案:

没有答案