本文介绍了Gradle构建成功,错误运行jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是gradle新手。
我正在用gradle构建一个项目。
它成功构建,没有任何错误。在运行build jar文件时,它给出了 classNotFoundException
。
我正在建立一个 spring.io中的spring项目然而,问题看起来类似于,但找不到,找不到一个办法。请帮助。
编辑:这就是我的 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'
}
仓库{
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile(org.springframework.boot:spring-boot-starter-web)
testCompile( junit)
}
任务包装器(类型:包装器){
gradleVersion ='2.3'
}
startScripts {
mainClassName ='申请on'
}
springBoot {
mainClass =Application
}
解决方案
您需要使用生成的启动脚本启动应用程序。他们会自动设置适当的类路径。
I am new to gradle.
I am building a project using gradle.It build successfully without any error. While running the build jar file it is giving classNotFoundException
.
I am building a simple spring project from spring.io
However question look similar to this but, could not find a solution. Please help.
edit: This is how my build.gradle
looks
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"
}
解决方案
You'll need to start the application with the generated start scripts. They will automatically take care of setting up the proper classpath.
这篇关于Gradle构建成功,错误运行jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!