【发布时间】:2017-08-10 21:10:47
【问题描述】:
我希望标题本身是描述性的,但为了清楚起见,我试图在 greeting-service 中包含 jar(即 error-handling-service.jar)之一。罐子。构建后,我在新项目(即TestApplication)中包含了 greeting-service.jar 但在执行 TestApplication 我得到了(顺便说一句,TestApplication 不是 gradle 项目)
Exception in thread "main" java.lang.NoClassDefFoundError: co/common/exception/BaseException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
co.common.exception.BaseException 是 error-handling-service 模块中的一个类
根据question 这里。我包括了
manifest {
attributes(
"Manifest-Version": "1.0",
"Class-Path": configurations.compile.collect { it.getName() }.join(' ')
)
}
这里是 greeting-service 的 build.gradle,它依赖于错误处理服务
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile('org.apache.commons:commons-lang3:3.0')
compile('org.apache.commons:commons-collections4:4.0')
compile('org.slf4j:slf4j-api:1.7.25')
compile('co.common:error-handling-service:1.0.0-SNAPSHOT')
testCompile("org.mockito:mockito-all:1.9.5")
testCompile('junit:junit:4.12')
}
jar {
baseName = 'greeting-service'
version = '1.0.0-SNAPSHOT'
manifest {
attributes(
"Manifest-Version": "1.0",
"Class-Path": configurations.compile.collect { it.getName() }.join(' ')
)
}
}
group = 'co.common'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
在成功构建 greeting-service 后,我在 TestApplication 中包含了 greeting-service.jar,但我仍然收到上述相同的异常。
Manifest-Version: 1.0
Class-Path: commons-lang3-3.0.jar commons-io-2.4.jar commons-collections
4-4.0.jar slf4j-api-1.7.25.jar error-handling-service-1.0.0-SNAPSHOT.
jar commons-logging-1.1.3.jar
为什么会发生这种情况,应该怎么做?
【问题讨论】:
标签: java gradle jar build.gradle