maven 工程项目打包 (jar包)
1:maven 打包的时候需要指定JDK版本,因为它默认版本太低,一些高级版本的语法可能不支持,就会在打包的时候报错。
2: 指定 maven项目jdk版本的方法我知道的有两种,第一种直接在pom文件中指定,在我们要用到的打包插件(plugin)中去配置,例如(红色字体部分,我指定的是JDK8):
<plugin>
<artifactId>maven-compiler-plugin</artifactId><configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>src\main\lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
第二种是在settings.xml(eclipse中可以在界面上方的工具栏中 点击 window--preferences--Maven--User Settings 界面右侧可以看到该文件的路径)文件中指定:
<profiles>
<profile>
<id>JDK1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
</properties>
</profile>
</profiles>
3: 我们的maven工程项目在打包时可能会包含第三方依赖包,而且有些依赖没有发布在maven仓库,可能是本地依赖的jar包,所以在打包时要指定我们要额外寻找依赖的路径,在pom文件中如下指定(我在本地项目创建的依赖包路径src\main\lib):
<plugin>
<artifactId>maven-compiler-plugin</artifactId><configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>src\main\lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
4:打包我分了两步,第一步打出本地项目的代码(不包含依赖),使用maven install 命令,eclipse的话,可以右键项目 run as maven install,打包完成之后控制台会输出打包完成的jar包所在目录。
第二部是要把项目中的依赖包打出来,可以参考 https://blog.csdn.net/andyliulin/article/details/46544555。
5: 分开打包的好处是 在我们自己的项目中可能已经引入了第三方jar包,这样我们在引入当前jar包的时候就可以剔除掉重复的jar包,避免不必要的jar包冲突。
细节不是很详细,有问题欢迎在评论区留言,谢谢。