Maven打成可執行Jar包

1、利用shade插件java

在pom.xml指定 shade插件,須要注意的是mainClass裏面內容是你的main函數所在的類的全限定名。apache

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.lubby.jar.ServiceMain</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


2、執行jar包maven

java -jar name.jar
相關文章
相關標籤/搜索