更新时间:2021-12-17 14:42:16
我遇到了同样的问题并且解决了它。
I had the same problem and just solved it.
起初我用 maven-assembly-plugin
生成胖罐,它创建了一个名为的文件mavenproject1-0.0.1-快照罐与 - dependencies.jar
。当我尝试运行它时,这个文件会出现同样的问题。
At first I was generating the fat jar with the maven-assembly-plugin
, which created a file called mavenproject1-0.0.1-SNAPSHOT-jar-with-dependencies.jar
. This file gave the same problem as you when I tried running it.
我认为因为它是一个Spring Boot应用程序,所以你需要使用它们的插件。我将包装更改为 spring-boot-maven-plugin
,并创建了两个文件: mavenproject1-0.0.1-SNAPSHOT.jar
和 mavenproject1-0.0.1-SNAPSHOT.jar.original
。只需尝试 java -jar target / mavenproject1-0.0.1-SNAPSHOT.jar
,它将有希望工作。 : - )
I think that because it's a Spring Boot application, you need to use their plugin. I changed my packaging to the spring-boot-maven-plugin
and it creates two files: mavenproject1-0.0.1-SNAPSHOT.jar
and mavenproject1-0.0.1-SNAPSHOT.jar.original
. Just try java -jar target/mavenproject1-0.0.1-SNAPSHOT.jar
and it will hopefully work. :-)
作为参考,这是我的pom.xml:
For reference, here is my pom.xml:
<?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.company</groupId>
<artifactId>mavenproject1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.company.common</groupId>
<artifactId>common-files</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.mavenproject1.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>