1.打包时附加外部Jar包
<!--编译+外部 Jar打包-->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/libs</extdirs>
</compilerArguments>
</configuration>
</plugin>
2.打包时附加源码
<!-- 源码打包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<!-- 完成绑定.执行完打包后执行 -->
<executions>
<execution>
<phase>package</phase>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
</plugin>
3.pom依赖打包
<!-- 依赖打包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<!--这部分可有可无,加上的话则直接生成可运行jar包-->
<!--<archive>
<manifest>
<mainClass>${exec.mainClass}</mainClass>
</manifest>
</archive>-->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
</execution>
</executions>
</plugin>
打包依赖的class文件命令:
mvn assembly:assembly
如果不希望依赖的JAR包变成CLASS
可以修改ASSEMBLY插件.本地地址一般是 ${user_home}\.m2\org\apache\maven\plugins\maven-assembly-plugin\2.4
打开此目录下的maven-assembly-plugin-2.4.jar,找到assemblies\jar-with-dependencies.xml 把里面的UNPACK改成FALSE即可