gpt4 book ai didi

maven - 使用 Maven Shade 插件创建可执行 JAR

转载 作者:行者123 更新时间:2023-12-02 05:18:56 25 4
gpt4 key购买 nike

我在从简单的 Java 程序制作可执行 jar 时遇到问题。

我关注了these Maven instructions并修改了我的 pom.xml:

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>package.MyClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

当执行 install 目标时,我可以读到这一行:

[INFO] Replacing /home/project-1.0.0.jar with /home/project-1.0.0-shaded.jar

但我在该位置只能找到 project-1.0.0.jar,它实际上包含依赖项 - 并且具有正确的大小 - 但是当尝试使用我的 jre 执行它时,它说:

The file '/home/project-1.0.0.jar' is not marked as executable.

因此什么都不会执行!

如何让我的 jar 正确执行?

感谢您的帮助!

最佳答案

Given is the pom.xml to create an executable jar file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.executablejar</groupId>
<artifactId>demo</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demo Maven Webapp</name>
<url>http://maven.apache.org</url>

<properties>
<java-version>1.8</java-version>
<docker.image.prefix>springDemo</docker.image.prefix>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>demo</finalName>
</build>

关于maven - 使用 Maven Shade 插件创建可执行 JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10964670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com