使用jar文件运行时出现java白标错误,但使用war文件和使用命令mvn springboot:run运行时效果良好
更新 我找到了另一个选择(从一个问题)。当我使用war文件运行项目时,它可以工作。java-jar项目。战争但我仍然不明白为什么它适用于war文件,为什么不适用于jar文件
我有一个SpringBoot项目,它在STS上运行良好,在创建jar文件时没有错误或警告。但是,当我使用命令java-jar项目通过命令行运行项目时。jar并通过浏览器访问,我得到了白标签错误
然后,我使用maven命令mvnspringboot:run运行该项目,它再次运行良好。没有错误。我在堆栈溢出上搜索了类似的问题,修改了jsp页面的前缀和后缀,但仍然不起作用。我在函数中编写了一个print语句来检查控制器是否确实被命中,并发现它实际上能够命中API并在方法中打印语句,但无法识别jsp页面
请帮助我确定我正在犯的错误,以及为什么它适用于maven命令,为什么不使用jar文件,或者如果我运行war文件,它是否有任何区别。以下是一些代码详细信息:
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.project</groupId>
<artifactId>Project.V-1.3</artifactId>
<version>V-1.3</version>
<name>Project</name>
<description>Project - Launching on AWS</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.36</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
应用程序。属性文件
spring.mvc.view.prefix=/WEB-INF/jsps/
spring.mvc.view.suffix=.jsp
我的控制器
@Controller
public class HomeController {
@RequestMapping("/")
public ModelAndView home() {
ModelAndView home_model = new ModelAndView();
System.out.println("Home Page is hit");
home_model.setViewName("homePage");
return home_model;
} }
我在CMD上看到以下内容:
但当它在浏览器上显示白色标签错误时,如图1所示
共 (0) 个答案