养成每日阅读好习惯, 每天进步, 超越昨天的自己
作者:有勇气的牛排
愿景:输出体系化编程知识与技巧,助力软件行业发展与从业者学习减负,让编程产生更大价值。
Linux专栏文章: Java文章专栏大全 | 有勇气的牛排
哈喽,大家好,我是有勇气的牛排。
很多小伙伴在学习Java的过程中,可能对Java Maven打包项目方法有点小迷惑,毕竟Java知识体系庞大,全背下来肯定是有点难度的,今天牛排在学习大数据的时候总结出了使用流程,再也不用背代码了,特此分享给大家。
有问题的小伙伴欢迎在文末评论,点赞、收藏是对我最大的支持!!!。
架包定义:指仅将代码打包到jar中,在运行的平台必须保证依赖。
方法:maven —> Lifecyle —> Clean —> Package
全包定义:将maven项目中的依赖于代码都打为一个包。
方法:maven —> Plugins —> assembly —>assembly:assembly
项目配置
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<groupId>groupIdgroupId>
<artifactId>azkaban_csartifactId>
<version>1.0-SNAPSHOTversion>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
<java.version>1.8java.version>
properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-assembly-pluginartifactId>
<configuration>
<appendAssemblyId>falseappendAssemblyId>
<descriptors>
<descriptor>assembly.xmldescriptor>
descriptors>
configuration>
<executions>
<execution>
<id>make-assemblyid>
<phase>packagephase>
<goals>
<goal>singlegoal>
goals>
execution>
executions>
plugin>
plugins>
build>
project>
新建主目录文件:assembly.xml
<assembly xmlns:xsi="" xmlns="" xsi:schemaLocation=" ">
<id>${project.version}id>
<formats>
<format>dirformat>
<format>tar.gzformat>
formats>
<includeBaseDirectory>falseincludeBaseDirectory>
<baseDirectory>${build.directory}baseDirectory>
<fileSets>
<fileSet>
<directory>conf/directory>
<outputDirectory>${project.artifactId}/confoutputDirectory>
fileSet>
<fileSet>
<directory>db/directory>
<outputDirectory>${project.artifactId}/dboutputDirectory>
fileSet>
<fileSet>
<directory>${build.directory}directory>
<includes>
<include>*.jarinclude>
includes>
<excludes>
<exclude>*sources.jarexclude>
excludes>
<outputDirectory>${project.artifactId}/liboutputDirectory>
fileSet>
<fileSet>
<directory>bin/directory>
<outputDirectory>${project.artifactId}/binoutputDirectory>
<fileMode>754fileMode>
<lineEnding>unixlineEnding>
fileSet>
fileSets>
assembly>
开始打包