使用MAVEN打JAR,直接使用
一、简单的方法:
首先在pom.xml里面添加:
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.qunar.piao.data.integration.Boot</mainClass> </manifest> <!-- 需要执行的main --> </archive> </configuration> </plugin> </plugins> </build>
然后执行:mvn assembly:assembly
最后执行:java -jar target/ticket-data-integration-0.0.1-SNAPSHOT-jar-with-dependencies.jar
二、执行任意main方法
两个类,Boot类:
package com.qunar.check.integration; public class Boot { public static void main(String[] args){ System.out.println("test xingxing"); } }
Boot2类:
package com.qunar.check.integration; public class Boot2 { public static void main(String[] args){ System.out.println("test liqiu"); } }
那么执行:
$ java -classpath target/check-jar-with-dependencies.jar com.qunar.check.integration.Boot2 test liqiu $ java -classpath target/check-jar-with-dependencies.jar com.qunar.check.integration.Boot test xingxing
两个main函数都可以执行
续:
如果你的项目包含Spring,那么打包可能就会遇到的麻烦,可以参考:http://www.cnblogs.com/liqiu/p/4508848.html