写这篇文件主要记录JRA文件里面究竟是什么?而后MANIFEST.MF又是什么?Springboot 如何只有Main方法就能够运行的?java
Java开发中JRA包中常常会看到这个文件中。Springboot打包也会生成对应的JRA,下图咱们用maven命令直接编译打包spring
执行mvn clean package -DskipTests=true -P test
,生成的文件以下
springboot
BOOT-INF
注意了这个是咱们本身写的代码生成的class和配置文件
META-INF
包含了MANIFEST.MF
和 maven
文件夹mybatis
maven文件夹下面包含pom.xml
和pom.properites
文件
pom.xml
是表明的整个项目引用的第三方jar的maven坐标,如Spring 等
pom.properites
是当前执行 package 命令后打包当前项目的版本信息,
就以下面,是否是简单明了呀。app
#Generated by Apache Maven #Fri May 29 16:56:23 CST 2020 version=1.0-SNAPSHOT groupId=com.xxx artifactId=xxxxxService
接下来看打包文件中的MANIFEST.MF
maven
Manifest-Version: 1.0 Implementation-Title: xxxxService Implementation-Version: 1.0-SNAPSHOT Archiver-Version: Plexus Archiver Built-By: tony Implementation-Vendor-Id: com.xx Spring-Boot-Version: 1.5.10.RELEASE Implementation-Vendor: Pivotal Software, Inc. Main-Class: org.springframework.boot.loader.JarLauncher Start-Class: com.xxx.xxxxApplication Spring-Boot-Classes: BOOT-INF/classes/ Spring-Boot-Lib: BOOT-INF/lib/ Created-By: Apache Maven 3.5.3 Build-Jdk: 1.8.0_144 Implementation-URL: http://projects.spring.io/spring-boot/xxxAdminService/
直接看上面的内容,遇到问题咱们先挑选容易的来看。spring-boot
一、 Manifest-Version
用来定义manifest文件的版本,例如:Manifest-Version: 1.0ui
二、Built-Bycode
三、Spring-Boot-Version
等等这些都是很简单的熟悉xml
一、Implementation-Title 定义了扩展实现的标题
二、 Implementation-Version 定义扩展实现的版本
三、 Implementation-Vendor 定义扩展实现的组织
四、 Implementation-Vendor-Id 定义扩展实现的组织的标识
五、 Implementation-URL : 定义该扩展包的下载地址(URL)
一、Spring-Boot-Classes: BOOT-INF/classes/
二、Spring-Boot-Lib: BOOT-INF/lib/
一、Main-Class
org.springframework.boot.loader.JarLauncher
这个很重要,很重要,是当前JRA的启动类, 定义jar文件的入口类,该类必须是一个可执行的类,一旦定义了该属性便可经过 java -jar x.jar来运行该jar文件。
二、Start-Class
com.jc.xxxApplication
这个是你本身项目的启动执行类的开始,我这里是Springboot的main方法的开始
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableScheduling @MapperScan(basePackages = "com.xxxxx.mapper") @SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) public class xxxxApplication { public static void main(String[] args) { SpringApplication.run(xxxxAdminApplication.class, args); } }
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package org.springframework.boot.loader; import org.springframework.boot.loader.archive.Archive; import org.springframework.boot.loader.archive.Archive.Entry; public class JarLauncher extends ExecutableArchiveLauncher { static final String BOOT_INF_CLASSES = "BOOT-INF/classes/"; static final String BOOT_INF_LIB = "BOOT-INF/lib/"; public JarLauncher() { } protected JarLauncher(Archive archive) { super(archive); } protected boolean isNestedArchive(Entry entry) { return entry.isDirectory() ? entry.getName().equals("BOOT-INF/classes/") : entry.getName().startsWith("BOOT-INF/lib/"); } public static void main(String[] args) throws Exception { (new JarLauncher()).launch(args); } }
看到上面的代码没有JarLauncher
,上面的第一张截图中红框标出来的,
这个就是 执行java -jar
的入口。这个类里面会加载咱们写代码编译出来的文件。
我这个JAR是Springboot项目打包生成的,JarLauncher
会加载上面第二张截图中的class 和配置文件。
你们有兴趣能够看看org/springframework/boot/loader
下面的类,这个包下面着重讲解了Springboot 如何只有Main方法就能够运行加载咱们编译的class和配置文件。
以上就是Springboot如何优雅运行java -jar xxx.jar