eclipse使用maven插件打包JAR包

不用插件直接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.
具体的配置的意思可以参考https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值