简体   繁体   中英

404 error when Running Jar [Spring Boot]

i'm stuck with a problem and can't figure what's wrong.

I have a multi-module maven project, using spring boot. Layout of the project

I'm using STS, and everything is fine. If i run the app, it runs the server, and i have my index in localhost:8080.

However, i'd like to generate a jar from this. So, i'm using mvn clean install . It generates a jar in /target. The layout in the jar is fine, with the source, and the source of the client . Then, i'm running my jar with java -jar myJar.jar . The server runs properly, but when i'm trying to access to the site, i have an error 404. It can't find the views.

The error :

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

Here's my pom.xml of the web and client module.

Client 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>

Module web 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>

I've search over stackoverflow but haven't find anything :/

If you need more details or code, ask me i'll edit.

Thanks !

Please check if you have any method attached to the url your are hitting from the browser. 404 - not found, the resource or url you are trying to access does not exists. You should have a Method of a controller mapped to "/" or whatever url you are hitting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM