maven打包jar,得到所有依赖,及设置主类
pom中加入
<plugin>
??? ??? ??? ??? <groupId>org.apache.maven.plugins</groupId>
??? ??? ??? ??? <artifactId>maven-jar-plugin</artifactId>
??? ??? ??? ??? <configuration>
??? ??? ??? ??? ??? <archive>
??? ??? ??? ??? ??? ??? <manifest>
??? ??? ??? ??? ??? ??? ??? <addClasspath>true</addClasspath>
??? ??? ??? ??? ??? ??? ??? <mainClass>youmainclasspath</mainClass>
??? ??? ??? ??? ??? ??? </manifest>
??? ??? ??? ??? ??? </archive>
??? ??? ??? ??? </configuration>
??? ??? ??? </plugin>
执行 mvn dependency:copy-dependencies -DoutputDirectory=lib package
然后把lib里的所有jar放到你工程的jar包所在的目录
运行java -jar youjar.jar
?
打分包:
<plugin>
??? ??? ??? ??? <groupId>org.apache.maven.plugins</groupId>
??? ??? ??? ??? <artifactId>maven-jar-plugin</artifactId>
??? ??? ??? ??? <version>2.3.1</version>
??? ??? ??? ??? <executions>
??? ??? ??? ??? ??? <execution>
??? ??? ??? ??? ??? ??? <id>pack-client</id>
??? ??? ??? ??? ??? ??? <phase>package</phase>
??? ??? ??? ??? ??? ??? <goals>
??? ??? ??? ??? ??? ??? ??? <goal>jar</goal>
??? ??? ??? ??? ??? ??? </goals>
??? ??? ??? ??? ??? ??? <configuration>
??? ??? ??? ??? ??? ??? ??? <classifier>client</classifier>
??? ??? ??? ??? ??? ??? ??? <includes>
??? ??? ??? ??? ??? ??? ??? ??? <include>com/test/*</include>
??? ??? ??? ??? ??? ??? ??? ??? <include>com/test/common/*/*</include>
??? ??? ??? ??? ??? ??? ??? </includes>
??? ??? ??? ??? ??? ??? </configuration>
??? ??? ??? ??? ??? </execution>
??? ??? ??? ??? ??? <execution>
??? ??? ??? ??? ??? ??? <id>pack-server</id>
??? ??? ??? ??? ??? ??? <phase>package</phase>
??? ??? ??? ??? ??? ??? <goals>
??? ??? ??? ??? ??? ??? ??? <goal>jar</goal>
??? ??? ??? ??? ??? ??? </goals>
??? ??? ??? ??? ??? ??? <configuration>
??? ??? ??? ??? ??? ??? ??? <classifier>server</classifier>
??? ??? ??? ??? ??? ??? ??? <archive>
??? ??? ??? ??? ??? ??? ??? ??? <manifest>
??? ??? ??? ??? ??? ??? ??? ??? ??? <addClasspath>true</addClasspath>
??????????????????????????? ??? ??? <classpathPrefix>lib/</classpathPrefix>
??? ??? ??? ??? ??? ??? ??? ??? ??? <mainClass>com.skymobi.openapi.util.Server</mainClass>
??? ??? ??? ??? ??? ??? ??? ??? </manifest>
??? ??? ??? ??? ??? ??? ??? </archive>
??? ??? ??? ??? ??? ??? </configuration>
??? ??? ??? ??? ??? </execution>
??? ??? ??? ??? </executions>
??? ??? ??? </plugin>