【发布时间】:2019-03-08 00:01:48
【问题描述】:
Gradle 文件:
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
maven { url 'http://repo1.maven.org/maven2' }
//maven { url 'https://mvnrepository.com/artifact/org.slf4j/slf4j-api' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
//compile("org.slfj4:slf4j-api:1.7.25")
//runtime('org.slfj4:slf4j-simple:1.7.26')
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7
repositories {
maven { url 'http://repo1.maven.org/maven2' }
//maven { url 'https://mvnrepository.com/artifact/org.slf4j/slf4j-api' }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.session:spring-session')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
runtime('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
runtime('org.hsqldb:hsqldb')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile('junit:junit:4.12')
//
// Dimensions dependencies
//
compile group: 'com.serena', name: 'darius', version:'1.0'
compile group: 'com.serena', name: 'dmfile', version:'1.0'
compile group: 'com.serena', name: 'dmnet', version:'1.0'
compile group: 'com.serena', name: 'dmpmcli', version:'1.0'
compile group: 'com.serena', name: 'dmclient', version:'1.0'
// log4j
compile group: 'log4j', name: 'log4j', version: '1.2.17'
// https://mvnrepository.com/artifact/javax.mail/mail
compile group: 'javax.mail', name: 'mail', version: '1.4.1'
// https://mvnrepository.com/artifact/commons-codec/commons-codec
compile group: 'commons-codec', name: 'commons-codec', version: '1.4'
// https://mvnrepository.com/artifact/javax.inject/javax.inject
compile group: 'javax.inject', name: 'javax.inject', version: '1'
//compile group: 'org.slf4j', name: '
}
task setHttpProxyFromEnv {
def map = ['HTTP_PROXY': 'http', 'HTTPS_PROXY': 'https']
for (e in System.getenv()) {
def key = e.key.toUpperCase()
if (key in map) {
def base = map[key]
def url = e.value.toURL()
println " - systemProp.${base}.proxy=${url.host}:${url.port}"
System.setProperty("${base}.proxyHost", url.host.toString())
System.setProperty("${base}.proxyPort", url.port.toString())
}
}
}
build.dependsOn setHttpProxyFromEnv
我在 eclipse 上手动添加了 slj4-api 和 simple 到我的类路径中,所以它可以在 eclipse 上运行,但是当我将它导出到一个可运行的 JAR 文件并尝试从命令提示符运行它时,它不断弹出这个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
是否有应该在命令提示符下运行的命令或者是 Eclipse 中的这个问题
【问题讨论】:
-
为什么要手动将它们添加到 Eclipse,而不是将它们添加到 Gradle 依赖项?
-
我曾经做过一次。我在依赖项下添加了 compile('org.slfj4:slf4j-api:1.7.25') ,它仍然无法从命令行运行
-
是错字吗?
slfj4 -
是的,这是一个错字,但这不是问题