![](/img/trans.png)
[英]Java spring boot jar file error when running maven package command
[英]404 error when Running Jar [Spring Boot]
我陷入了一个问题,无法弄清楚出了什么问题。
我有一个使用Spring Boot的多模块Maven项目。 项目布局
我正在使用STS,一切都很好。 如果我运行该应用程序,它将运行服务器,并且我在localhost:8080中拥有索引。
但是,我想从中生成一个jar。 因此,我正在使用mvn clean install 。 它在/ target中生成一个jar。 jar中的布局很好,带有源和client的源 。 然后,我用java -jar myJar.jar运行我的jar。 服务器正常运行,但是当我尝试访问该站点时,出现错误404。找不到视图。
错误 :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Dec 28 19:45:52 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available
这是我的Web和客户端模块的pom.xml。
客户端pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>projet.si</groupId>
<artifactId>projetsi</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>projet.si</groupId>
<artifactId>ProjetSI_client</artifactId>
<name>ProjetSI_client</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
</resource>
<resource>
<directory>${project.build.directory}/dist</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/classes/</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
网络模块pom.xml:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>projet.si</groupId>
<artifactId>projetsi</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>projet.si</groupId>
<artifactId>ProjetSI_web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ProjetSI_web</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>projet.si</groupId>
<artifactId>ProjetSI_business</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>projet.si</groupId>
<artifactId>ProjetSI_client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<configuration>
<outputDirectory>${project.build.directory}/dist/</outputDirectory>
<includeArtifactIds>ProjetSI_client</includeArtifactIds>
<includeGroupIds>projet</includeGroupIds>
<includes>**/*</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我已经搜索了stackoverflow但没有找到任何东西:/
如果您需要更多详细信息或代码,请问我,我将进行编辑。
谢谢 !
请检查是否有任何方法附加到您从浏览器中命中的网址。 404-找不到,您尝试访问的资源或网址不存在。 您应该将控制器的“方法”映射到“ /”或您要命中的任何URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.