我希望标题本身是描述性的,但要清楚,我想包括一个jar
(即错误处理 - service.jar中)在问候服务。罐子。构建之后我列入新的项目(即TestApplication),但在执行TestApplication我收到的问候,service.jar中(顺便说一句,TestApplication不是gradle这个项目)摇篮:添加类的JAR文件的类路径
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是一个类错误处理服务模块
按照question在这里。我包括
manifest {
attributes(
"Manifest-Version": "1.0",
"Class-Path": configurations.compile.collect { it.getName() }.join(' ')
)
}
这里是问候服务的的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'
}
问候服务的成功构建后,我包括在TestApplication问候,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
为什么会发生这种情况,应该怎么办?
jar的内容不包含error-handling-service-1.0.0-SNAPSHOT.jar的类。但是,这是我想知道我的配置看起来不错,或者我失去了一些东西? –
你的构建文件看起来不错。但是错误是由于缺少类co/common/exception/BaseException造成的。因此,您应该将包含此类的.jar文件包含到构建路径中。或者你可以从你的代码中删除这个类的用法。您可以使用'gradle dependencies'命令检查您的gradle项目的实际依赖关系 –