【问题标题】:Spring boot where is my jar fileSpring Boot 我的 jar 文件在哪里
【发布时间】:2019-02-01 10:17:20
【问题描述】:

Spring Boot 让设置一个简单的应用程序变得非常容易。 但是我需要更长的时间才能真正获得一个可以上传到远程服务器的 jar 文件。 我正在使用 IntelliJ,没有命令行,我使用 gradle。该应用程序以某种方式在 Intellij 之外运行。但是创建的文件在哪里? Bootjar 中的 jar 在哪里?

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-spring-boot'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")

    compile("org.springframework.boot:spring-boot-starter-actuator")

    testCompile("org.springframework.boot:spring-boot-starter-test")

    // add spring data repos
    compile("org.springframework.boot:spring-boot-starter-data-jpa")

    compile("org.postgresql:postgresql:42.2.4")

    // REST interface
    compile("org.springframework.boot:spring-boot-starter-data-rest")

    // Security
    compile("org.springframework.boot:spring-boot-starter-security")
}

更新:添加了项目结构的图片:

更新 2:文件夹结构:

【问题讨论】:

    标签: java spring-boot jar


    【解决方案1】:

    如果您只是在 IDE 中运行它,则不会创建 jar。为此,您需要从 IDE 或命令行运行 gradle 构建(在您的情况下)以将其构建到 jar 中。

    从命令行转到您的项目目录并输入:

    ./gradlew build
    

    这会执行 gradle 包装器,它应该下载运行构建所需的所有内容,然后执行构建。

    然后你会在build/lib找到你的罐子

    【讨论】:

    • 好的,我在文件夹中打开了 cmd 并调用了“gradlew build”。现在我在 /build/libs 中有一个带有 jar 的构建目录。 IntelliJ 也可以做到这一点吗?
    • @Todd 我正在使用 Intellij Idea CE 但在构建文件夹中,我没有看到 libs 文件夹。是的,当我们从终端执行此操作时,我们可以看到为什么不在 Intellij 中
    猜你喜欢
    • 1970-01-01
    • 2017-11-19
    • 2017-05-28
    • 2015-11-05
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    相关资源
    最近更新 更多