我正在使用 Java + Gradle(内置于 intellij idea)('gradle' = 'sh gradlew')
在编辑器中或执行时gradle run
一切正常,但是当我尝试编译gradle build
和运行时,调用时java -jar ./build/libs/LinearServer-1.0-SNAPSHOT.jar
出现错误Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
Logger.getLogger(Main.class);
build.gradle 文件代码:
plugins {
id 'java'
id 'application'
}
group 'ru.screamt5.linear'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
mainClassName = 'ru.screamt5.linear.LinearServer.Main'
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'com.google.inject', name: 'guice', version: '4.2.0'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar {
manifest {
attributes(
'Main-Class': mainClassName,
'Class-Path': configurations.compile.collect { it.getName() }.join(' ')
)
}
}
可能是什么问题呢?
需要从添加到jar