1.配置pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<!--编译的jdk版本-->
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<!--maven打包jar插件-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<!--打包的时候 ,将依赖一起打包-->
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!--主类-->
<mainClass>com.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id><!-- this is used for inheritance merges -->
<phase>package</phase><!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
命令打包
1.mvn clean
2.mvn package
打包结束查看
在项目target目录下
xxxxx-0.0.1-SNAPSHOT-jar-with-dependencies.jar
新建个目录放进去,然后运行命令
jar -xvf xxxxx-0.0.1-SNAPSHOT-jar-with-dependencies.jar
解压jar包,有一个META-INF 目录下的MANIFEST.MF 文件记录着打包的内容,版本号,jdk版本,主类等信息。