从 STS(spring 工具套件)运行时,应用程序启动并正常工作,但是当我尝试使用 java -jar 运行它时,出现异常。我究竟做错了什么?如果它在 STS 中运行良好,那么当我在 tomcat 上部署这个 .war 时,它也运行良好;为什么它不能与 java -jar 一起使用?有什么建议吗?以下是我的 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.xyz</groupId> <artifactId>youtubeservice</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>YoutubeService</name> <description>YoutubeService</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.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> <maven.test.skip>true</maven.test.skip> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</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>
2 回答
慕容708150
TA贡献1831条经验 获得超4个赞
Spring Boot 参考指南中的Create an Executable JAR with Maven部分很好地解释了这一点。主要是你必须像这样使用Spring Boot Maven 插件:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.my.mainClass</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
添加回答
举报
0/150
提交
取消