[英]Gradle dependencies not being exported to runnable jar by eclipse
I am trying to export my gradle eclipse project to a runnable jar, however it's dependencies are not being bundled into the runnable jar itself. 我正在尝试将gradle eclipse项目导出到可运行的jar中,但是它的依赖项并未被捆绑到可运行的jar中。
I file -> export -> runnable jar -> Extract required libraries into generated jar. 我归档->导出->可运行的jar->将所需的库提取到生成的jar中。
They are correctly exported if I manually do "add external jar" from the configure build path option, however I want to do this via gradle, and they are not correctly exported without the manual add. 如果我从configure build path选项手动执行“添加外部jar”,则可以正确导出它们,但是我想通过gradle进行此操作,并且如果没有手动添加,则无法正确导出它们。
I have tried to do a gradlew clean, and gradlew build. 我试图做一个gradlew清洁,并建立gradlew。 I have refreshed my gradle dependencies, and I have rebuilt the project, as well as cleaned it via the eclipse project -> clean option.
我已经刷新了gradle的依赖关系,并且重新构建了该项目,并通过eclipse project-> clean选项对其进行了清理。
Below is my build.gradle file: 以下是我的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) } }
}
When I look into the jar generated, I see that it doesn't contain the dependencies inside it, and when I go to run the jar via java -jar jar.jar, I get a NoClassDefFound error. 当我查看生成的jar时,我发现它里面不包含依赖项,并且当我通过java -jar jar.jar运行jar时,出现了NoClassDefFound错误。 I want to get all my gradle dependencies bundled into a runnable jar so I can do a java -jar jar.jar and have my jar run as if I had hit run in the eclipse editor.
我想将所有gradle依赖项捆绑到一个可运行的jar中,这样我就可以执行java -jar jar.jar并让我的jar运行,就像在Eclipse编辑器中命中运行一样。
The build tools itself will create the runnable jar. 构建工具本身将创建可运行的jar。
gradle clean
gradle taskName
Project Jar will be created under folder : Project Jar将在以下文件夹中创建:
$project/build/libs/ folder.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.