问题描述
我通过 Exposed DAO 集成了 PostgreSQL 支持,在 IDE (Idea) 中一切顺利,但是在编译 jar 文件后,我开始遇到奇怪的错误,我在 Google 和这里都找不到。
这是导致问题的代码块:
fun main(args: Array<String>) {
var appConfigPath: String
val logger = logger("main")
val version = "0.0.3-alpha"
// Sentry initializer
try {
throw Exception("Application initialized")
} catch (e: Exception) {
logger.info(e)
}
// Parse command line arguments
...
val dataSource = try {
PGDataSource().apply {
serverName = appConfig.db.serverName
databaseName = appConfig.db.databaseName
user = appConfig.db.user
password = appConfig.db.password
}
} catch (e: Exception) {
logger.fatal("Unable to create data source",e)
exitProcess(-1)
}
这是我在命令行上得到的:
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.impossibl.postgres.jdbc.DataSourceSettings.<clinit>(DataSourceSettings.java:50)
at com.impossibl.postgres.jdbc.AbstractDataSource.<init>(AbstractDataSource.java:73)
at com.impossibl.postgres.jdbc.AbstractGeneratedDataSource.<init>(AbstractGeneratedDataSource.java:12)
at com.impossibl.postgres.jdbc.PGDataSource.<init>(PGDataSource.java:50)
at com.mazekine.pay2say.MainKt.main(Main.kt:105)
Caused by: java.lang.IllegalArgumentException: Unable to parse setting "ssl.key.password.callback" from 'com.impossibl.postgres.protocol.ssl.ConsolePasswordCallbackHandler'
at com.impossibl.postgres.system.Setting.fromString(Setting.java:692)
at com.impossibl.postgres.system.Setting.init(Setting.java:554)
at com.impossibl.postgres.system.SystemSettingsInit.init(SystemSettingsInit.java:36)
at com.impossibl.postgres.system.SystemSettings.<clinit>(SystemSettings.java:354)
... 5 more
该应用程序是通过 Adpot-OpenJDK 使用 Java 11 目标编译的。
第一个错误是处理log4j2
。我尝试了 here 提出的所有解决方案,但这没有帮助,所以我认为主要问题来自 Exposed DAO,但我可能错了。
至于 DAO 本身,我从配置文件初始化到本地 PostgreSQL 13 数据源的连接:
{
"db": {
"server_name": "localhost","database_name": "silence","user": "silence_connect","password": "test1234"
}
}
最奇怪的是,在 IntelliJ Idea 内部一切正常,在我通过 Shadow 编译 jar 后,它停止工作。
这里还有包含所有依赖项的 build.gradle.kts
:
plugins {
kotlin("jvm") version "1.4.31"
application
java
id("com.github.johnrengelman.shadow") version "6.1.0"
}
group = "com.mazekine"
version = "0.0.2-alpha"
// Version variables
val novaLibVersion = "0.0.5-alpha"
val telegramBotVersion = "6.0.1"
val exposedVersion = "0.29.1"
val pgJDBCVersion = "0.8.6"
val jvmTargetVersion = "11"
repositories {
mavenCentral()
jcenter()
maven { url = uri("https://jitpack.io") }
}
dependencies {
implementation(kotlin("stdlib","1.3.0"))
implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.0")
// Broxus
implementation("com.broxus:nova-lib:$novaLibVersion")
// Kotlin Telegram Bot
implementation("io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:$telegramBotVersion")
// Exposed
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
implementation("com.impossibl.pgjdbc-ng:pgjdbc-ng:$pgJDBCVersion")
// Logging
implementation("org.apache.logging.log4j:log4j-api-kotlin:1.0.0")
implementation("org.apache.logging.log4j:log4j-api:2.13.3")
implementation("org.apache.logging.log4j:log4j-core:2.13.3")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.13.3")
implementation("org.apache.logging.log4j:log4j-to-slf4j:2.13.3")
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("ch.qos.logback:logback-core:1.2.3")
implementation("io.sentry:sentry-log4j2:4.2.0")
// State machine
implementation("com.ToxicBakery.kfinstatemachine:kfin:4.3.50")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}.forEach {
it.kotlinOptions { freeCompilerArgs = listOf("-Xnew-inference") }
}
application {
mainClassName = "com.mazekine.pay2say.MainKt" // Have to leave it here until shadowJar fixes the compatibility bug
mainClass.set("com.mazekine.pay2say.MainKt")
}
val compileKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = jvmTargetVersion
}
val compileTestKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = jvmTargetVersion
}
tasks.jar {
archiveBaseName.set("pay2say")
archiveVersion.set("")
archiveClassifier.set("")
archiveExtension.set("jar")
manifest.attributes["Main-Class"] = "com.mazekine.pay2say.MainKt"
}
tasks.shadowJar {
archiveBaseName.set("pay2say")
archiveVersion.set("")
archiveClassifier.set("")
archiveExtension.set("jar")
minimize()
}
知道我做错了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)