运行Jar [Spring Boot]

时间:2016-12-28 19:00:07

标签: java spring maven spring-boot jar

我遇到了问题,无法弄清楚是什么问题。

我有一个使用spring boot的多模块maven项目。 Layout of the project

我正在使用STS,一切都很好。如果我运行应用程序,它运行服务器,我的索引在localhost:8080。

但是,我想从中生成一个罐子。所以,我正在使用 mvn clean install 。它在/ target中生成一个jar。 jar中的布局很好,有源和source of the 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>

模块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>

我搜索了stackoverflow但没找到任何东西:/

如果您需要更多详细信息或代码,请告诉我我将进行编辑。

谢谢!

1 个答案:

答案 0 :(得分:0)

请检查您是否从浏览器访问的URL附加了任何方法。 404-找不到,您尝试访问的资源或网址不存在。您应该将控制器的“方法”映射到“ /”或您要击中的任何URL。