我的应用程序出现异常行为。
从IDE(Intellij)中启动主类工作正常。
使用
mvn spring-boot:run
该应用程序也可以正常运行。
但是当尝试从jar启动应用程序时,我得到了
java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
由于我的最终目标是使其与Docker一起使用,所以我希望它与以下设备一起运行:
java -jar ./target/mail-business-1.0-SNAPSHOT.jar
检查了几篇文章之后,我检查了相关性,删除了目标文件夹,以便可以重新创建它,但问题仍然存在。
会有人有主意吗?我正在考虑某些依赖项兼容性,但到目前为止我进行的测试均未成功
下面是我的pom.xl
<?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>
<artifactId>mail-business</artifactId>
<groupId>org.mail</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<!-- ===== Bibliothèques tierces ===== -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.bval/bval-jsr -->
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr</artifactId>
<version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/javax.mail-api -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.2.RELEASE</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>java/</classpathPrefix>
<mainClass>org.mail.impl.ScheduledTasks</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- plugin 4- apache cxf codegen wsdl2java goal -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<configuration>
<sourceRoot>generated/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>
https://raw.githubusercontent.com/xbreizh/troparo/e481ca9c19f78656678dfab01ca1a01f124c72e2/troparo-web/src/main/resources/org/troparo/web/services/MailService.wsdl
</wsdl>
</wsdlOption>
<wsdlOption>
<wsdl>
https://raw.githubusercontent.com/xbreizh/troparo/e481ca9c19f78656678dfab01ca1a01f124c72e2/troparo-web/src/main/resources/org/troparo/web/services/ConnectService.wsdl
</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
预先感谢
答案 0 :(得分:0)
我在本地尝试过,并通过添加以下内容使其起作用:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
,然后在“清理”之后运行“安装”或“软件包”。
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
从本质上讲,该插件似乎没有重新创建您的原始jar。如果您查看/ target /,现在应该看到一个.jar.original。