我在执行构建的jar文件时遇到问题:
运行以下命令 java -jar /build/libs/***.jar
给了我一堆 NoClassDefFoundError
错误 .
但是当我运行 gradle bootrun
它工作正常...
我在这里按照说明操作:http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html
我的build.gradle看起来像这样:
apply plugin: 'spring-boot'
sourceCompatibility = 1.5
version = '1.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
}
}
springBoot {
mainClass = "org.gradle.App"
}
dependencies {
compile files('lib/selenium-server-standalone-2.47.1.jar')
}
谢谢 .
1 回答
如果没有一些元素缺失,可能有点难以回答;如果你有一些花哨的东西,请突出或更好地分享你的应用程序,但基本上我能够使它与以下工作:
build.gradle文件非常像你的
我不知道它们是否有很大不同,但1.2.6版本的文档是http://docs.spring.io/spring-boot/docs/1.2.6.RELEASE/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-dependencies-without-versions,他们确实提到添加依赖项 .
关于你的脚本的说明,只有你的测试才需要硒吗?您可以将
compile files ..selenium
更改为testCompile files ..selenium
(甚至testRuntime
)您的jar文件将会感谢您 .有关信息,我为此测试构建了一个非常基本的Spring-Boot应用程序(基于Spring Boot In Action中的示例)
重要的是确保您拥有有效的
main
方法作为参考,我的gradle执行是
最后运行你的命令
如果您有问题,请确保在进行一些更改后运行
gradle clean
.