一.原生Java项目
1.pom文件中引用第三方外部依赖包![](https://img-blog.csdnimg.cn/791f3bfdb8244baca88c39d2be10056a.png)
<dependency>
<groupId>com.aig</groupId>
<artifactId>aiapt</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aiapt-1.0.jar</systemPath>
</dependency>
2.1在pom.xml 文件中配置,将依赖的 jar 包package到指定的文件夹中
maven-dependency-plugin:maven管理依赖打包plugin
<!-- 这里相当于将第三方依赖在打包的时候,将第三方jar包放到了target下指定的lib文件夹里,但是没有打到jar包内。 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<!-- 包含scope=system的dependency -->
<includeScope>system</includeScope>
</configuration>
</execution>
</executions>
</plugin>
2.2在pom.xml配置文件中分离项目包和第三方依赖包
<!--拷贝第三方依赖文件到指定目录-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!--分离项目包和依赖包-->
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<silent>true</silent>
</configuration>
</execution>
</executions>
</plugin>
3.在pom文件中配置编译的路径,jdk版本和字符编码集
maven-compiler-plugin:maven管理编译的plugin
<!-- 配置编译的路径,jdk版本和编码集 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<!-- 编译时使用 libs 目录下的 jar 包 -->
<configuration>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
<compilerArguments>
<extdirs>${project.basedir}/libs</extdirs>
</compilerArguments>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
4.在pom.xml 文件中配置,项目打jar 包时,将依赖的 jar 包一起并入到项目 jar 包中
maven-assembly-plugin:maven装配项目jar的plugin
<!-- 这里相当于将第三方jar包一起并入到项目jar包中去了。-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>xxx.xxx.xxx</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- 指定在打包节点执行jar包合并操作 -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Jar包目录结构
第三方依赖包package到根目录下
MANIFEST.MF文件
二.springboot项目
1.在pom配置文件中,package项目包的时候去除依赖包(springboot默认是将依赖包打进项目包里面的)
<!--打包时去除第三方依赖-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>non-exists</groupId>
<artifactId>non-exists</artifactId>
</include>
</includes>
<!-- 指定SpringBoot程序的main函数入口类 -->
<mainClass>com.aiatss.empf.Application</mainClass>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Jar包目录结构
第三方依赖包package到根目录的BOOT-INF/lib下
MANIFEST.MF文件
三.Bat Call Jar
原生Java项目Bat
-Xbootclasspath:完全取代系统Java classpath.最好不用。
-Xbootclasspath/a: 在系统class加载后加载。一般用这个。
-Xbootclasspath/p: 在系统class加载前加载,注意使用,和系统类冲突就不好了.
-cp xxx.jar "启动类":指定Main-class项目的入口
--empf.encrypt.password=xxxx:只是一串字符串作为参数传进来,可以在
public static void main(String[] args)的args里面接收到
Springboot分离了项目包和依赖包Bat
-Dloader.path=./lib/:加载外部的lib包