Spring Boot 应用程序在 STS 中工作但无法使用 java -jar 启动

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


富国沪深
浏览 246回答 2
2回答

慕容708150

Spring Boot 参考指南中的Create an Executable JAR with Maven部分很好地解释了这一点。主要是你必须像这样使用Spring Boot Maven 插件:<plugin>&nbsp; <groupId>org.springframework.boot</groupId>&nbsp; <artifactId>spring-boot-maven-plugin</artifactId>&nbsp; <configuration>&nbsp; &nbsp; <mainClass>com.my.mainClass</mainClass>&nbsp; </configuration>&nbsp; <executions>&nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; <goal>repackage</goal>&nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; </execution>&nbsp; </executions></plugin>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java