gpt4 book ai didi

java - Mvn clean package 未正确创建 JAR 文件

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:52 24 4
gpt4 key购买 nike

note: I tried out the suggested answers in the "possible-duplicated"-questions, they did sadly not help me. I edited my question a bit.

我设置了一个 Spring-Boot 应用程序(可以从 Spring Tool Suite IDE 执行)。现在我想构建 jar 文件并执行它。我尝试过的:

cd %path_to_my_project_root%
mvn clean package
cd target
java -jar myApp.jar

错误是(翻译后,可能是错误的措辞):

no main manifest attribute in myApp.jar

我尝试了不同平台上建议的不同解决方案(例如 herehere )。然而,据我了解,这似乎是我的 POM.xml 的问题。

我的Pom:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.demo</groupId>
<artifactId>myApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>myApp</name>
<description>desc</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<type>jar</type>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>ng</executable>
<workingDirectory>src/main/ui</workingDirectory>
<argument>
<argument>build</argument>
</argument>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

我查找了我的 Manifest.MF,内容如下:

Manifest-Version: 1.0
Implementation-Title: myApp
Implementation-Version: 0.0.1-SNAPSHOT
Built-By: me
Implementation-Vendor-Id: myPackage
Created-By: Apache Maven 3.6.0
Build-Jdk: 1.8.0_191
Implementation-URL: my_Url

我似乎缺少什么:

我查找了 jar 文件,我注意到了一些事情:

  • 我缺少 .jar.original 文件
  • 我的 Manifest.MF 中没有 Spring-Boot-VersionMain-ClassStart-ClassBoot-Inf 参数
  • 我的jar仅包含三样东西:META-INFcom(已编译的类)和application.properties文件。里面通常还有很多东西。

我的应用程序属性

spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://external.url/dbname?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=user
spring.datasource.password=pass

spring.jpa.database = MYSQL
spring.jpa.show-sql = true

最佳答案

您缺少此 Maven 属性:

<start-class>com.demo.MainClass</start-class>

(这必须包含调用 SpringApplication.run(..) 的主类)

关于java - Mvn clean package 未正确创建 JAR 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648762/

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