关于java jar包说明

复杂的java应用,或者library,最终会以jar文件形式发布。

jar分为两种:

FatJar (JDK自己的)

包含应用程序所有内容,包括配置等资源文件、依赖其它lib的jar文件
mvn package默认打出来的包。平常我们我们打的包,都是FatJar

FatJar存在形式,如下:

  • jar包类型。通过pom.xml中jar指定
  • war包类型。通过pom.xml中war指定

ThinJar(Spring提供的)

仅包含核心代码。其它资源文件、依赖其它lib的jar文件不在生成的jar包内。

ThinJar启动时,通过-Dloader.path=${resources_path},${lib_path}来指定并引用。
这种启动方式,是PropertiesLauncher机制。

PropertiesLauncher,默认从当前目录或者classpath,寻找loader.properties文件。
也可以通过System properties变量loader.config.location来设置loader.properties文件的位置。
如果文件不存在,也可以通过System properties来制定相关变量(loader.properties文件中的变量)的值

loader.properties文件内容主要包含两个变量,如下:

  • loader.path: a comma-separated list of directories (containing file resources and/or nested archives in *.jar or *.zip or archives) or archives to append to the classpath. BOOT-INF/classes,BOOT-INF/lib in the application archive are always used
  • loader.main: the main method to delegate execution to once the class loader is set up. No default, but will fall back to looking for a Start-Class in a MANIFEST.MF, if there is one in ${loader.home}/META-INF.

ThinJar存在形式,如下(同FatJar):

  • jar包类型。通过pom.xml中jar指定
  • war包类型。通过pom.xml中war指定

另外,还需要在pom.xml中spring-boot-maven-plugin进行配置:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
    <fork>true</fork>
    <layout>ZIP</layout>
 </configuration>
</plugin>xml

关于PropertiesLauncher,请参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值