maven项目多个main函数打包并运行jar包方式

瘦欲@ 提交于 2020-01-15 19:09:31

pom.xml

<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>
                        <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>dbOperate.DBMain</mainClass> //默认的主程序入口
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

打包命令 mvn package (加clean貌似会报错)

生成一个jar: test-1.0-SNAPSHOT.jar

运行方式:java -jar test-1.0-SNAPSHOT.jar 是执行默认的主程序,即dbOperate.DBMain

在项目中我还有一个main函数,matchDatasClean.MatchDataClean,若要执行它,

可以: java -cp test-1.0-SNAPSHOT.jar matchDatasClean.MatchDataClean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!