【问题标题】:Gradle build successful, error running jarGradle构建成功,运行jar时出错
【发布时间】:2015-10-04 17:49:45
【问题描述】:

我是 gradle 新手。

我正在使用 gradle 构建一个项目。 它构建成功,没有任何错误。在运行构建 jar 文件时,它会给出classNotFoundException

我正在从 spring.io 构建一个simple spring 项目

但是问题看起来类似于this,但是找不到解决方案。请帮忙。

编辑:这就是我的build.gradle 的样子

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

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

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

startScripts {
  mainClassName = 'Application'
}

springBoot {
  mainClass = "Application"
}

【问题讨论】:

    标签: java spring gradle classnotfoundexception


    【解决方案1】:

    您需要使用生成的启动脚本启动应用程序。他们会自动负责设置正确的类路径。

    【讨论】:

    • 谢谢!它应该是什么。我的主要功能在Application.java
    • 运行gradle installDist 以在build/install/projectName 中创建应用程序的映像。你会在那里找到脚本。
    • @BenjaminMuschko 它给了我一个大约 150 行长的脚本。我是新手,你能告诉我如何使用那些生成的启动脚本启动应用程序吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多