gpt4 book ai didi

java - 无法找到或加载主类 jar intellij

转载 作者:行者123 更新时间:2023-11-30 06:41:03 24 4
gpt4 key购买 nike

在我完成我的 spring-boot 服务器后,我想将其制作为一个 jar,以便我可以将其部署到远程服务器上。我选择用maven来做这件事

创建 .jar-with-dependecies.jar 后,我将其上传到服务器上并尝试运行

java -jar buyme-0.0.1-SNAPSHOT-jar-with-dependencies.jar

和其他人一样,我得到了

Error: Could not find or load main class com.buyme.BuymeApplication

我尝试了这里的答案:

Link 1

Link 2

Link 3

Link 4

似乎没有什么效果。这是我的

pom.xml

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.buyme.BuymeApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Manifest

Manifest-Version: 1.0
Main-Class: com.buyme.BuymeApplication

This is the project structure

enter image description here

mvn commands:

mvnc clean install (sometimes i tried assembly:assembly with the other two)

这也不起作用:

java -cp <name>.jar com.buyme.BuymeApplication

最佳答案

我设法解决了这个问题:

我用了this答案:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - 无法找到或加载主类 jar intellij,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44369531/

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