java - Gradle 依赖项没有被 Eclipse 导出到可运行的 jar
问题描述
我正在尝试将我的 gradle eclipse 项目导出到一个可运行的 jar,但是它的依赖项没有被捆绑到可运行的 jar 本身中。
我文件 -> 导出 -> 可运行的 jar -> 将所需的库提取到生成的 jar 中。
如果我从配置构建路径选项手动执行“添加外部 jar”,它们会正确导出,但是我想通过 gradle 执行此操作,并且如果没有手动添加,它们不会正确导出。
我试图做一个 gradlew clean 和 gradlew build。我刷新了我的 gradle 依赖项,并重建了项目,并通过 eclipse 项目 -> clean 选项对其进行了清理。
下面是我的 build.gradle 文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE")
}
}
plugins {
id 'java'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-activemq")
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.json:json:20171018'
compile 'org.mongodb:mongo-java-driver:3.6.4'
compile group: 'com.github.jai-imageio', name: 'jai-imageio-core', version: '1.4.0'
compile files ('../libs/CommonUtils.jar')
compile files ('../libs/UMS.jar')
compile files ('../libs/Cache.jar')
}
jar {
from { configurations.runtime.collect { zipTree(it) } }
}
当我查看生成的 jar 时,我发现它不包含其中的依赖项,当我通过 java -jar jar.jar 运行 jar 时,我收到 NoClassDefFound 错误。我想将我所有的 gradle 依赖项捆绑到一个可运行的 jar 中,这样我就可以执行 java -jar jar.jar 并让我的 jar 运行,就像我在 eclipse 编辑器中点击运行一样。
解决方案
构建工具本身将创建可运行的 jar。
gradle clean
gradle taskName
项目 Jar 将在文件夹下创建:
$project/build/libs/ folder.
推荐阅读
- wordpress - Ionic 3 推送通知错误 "statusText":"Unknown Error","name":"HttpErrorResponse","message":"(未知 url)的 Http 失败响应
- scala - 如何使用 spark 将来自 kafka 主题的流数据写入 hdfs?
- phpbb3 - phpbb删除了所有非活动用户现在无法登录
- php - 我正在尝试在启动时编写自定义 Laravel 函数,但出现错误
- c - 在 C 中释放具有清理属性的二维数组的通用函数
- python - 二维列表的总和
- windows-7 - 在 Windows 7 上运行 Postman 时出现黑窗
- php - 为什么我不能从管理员视图更新帖子元?
- javascript - 破解 AngularJS 表单元素以更改值
- javascript - 如何使用 chrome 配置文件“managed_javascript_blocked_for_urls”阻止第三方 JS