Java -jar 命令启动项目时,会去读取META-INF/MANIFEST.MF中的Main-Class属性值。
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: ls
Created-By: Apache Maven 3.6.0
Build-Jdk: 1.8.0_361
Main-Class: polymorphism.Client
如何指定Main-Class值?(两种方式)
都是在pom文件中通过<mainClass>标签指定值。
第一种:
<build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding><showDeprecation>true</showDeprecation></configuration><version>3.8.0</version></plugin><plugin><artifactId>maven-jar-plugin</artifactId><version>3.0.2</version><configuration><archive><manifest><mainClass>polymorphism.Client</mainClass></manifest></archive></configuration></plugin></plugins></build>
第二种:
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>2.3</version><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><transformers><transformerimplementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"><!--指定main方法--><mainClass>polymorphism.Client</mainClass></transformer></transformers></configuration></execution></executions></plugin></plugins></build>
为什么指定后,就可以生成Main-Class属性了呢?
这两种方式分别是通过什么方式达到效果的呢?