不用插件直接maven install ,不能执行,“找不到或者无法加载主类,XX中没有主清单属性”之类的。用java -cp 貌似也不太行,没细究。
jar包里面的Manifest.mf文件
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: 。。。。
Created-By: Apache Maven 3.2.1
Build-Jdk: 1.8.0
如何得到可执行的jar包 呢?需要用插件,网上查查maven-shade-plugin可能比较好用pom.xml的部分配置
<build>
<plugins><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xxx.xxx.main.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
run as maven install 之后生成的jar包里面的文件。
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By:........
Created-By: Apache Maven 3.2.1
Build-Jdk: 1.8.0
Main-Class: com.xxx.xxx.main.Main
==================================================
Setting Manifest Entries with the ManifestResourceTransformer
The ManifestResourceTransformer allows existing entries in the MANIFEST to be replaced and new entries added.
For example, the following sample sets
- the Main-Class entry to the value of the app.main.class property,
- the X-Compile-Source-JDK entry to the value of the maven.compile.source property and
- the X-Compile-Target-JDK entry to the value of the maven.compile.target property.