簡體   English   中英

Apache Fat 處的 Camel Timer Nullpointer 異常 Jar

[英]Apache Camel Timer Nullpointer exception at Fat Jar

我正在嘗試在 Gradle 項目中使用 Camel 3.5 實現一個計時器,接下來是 OpenJDK8

     from("timer://watchexpiration?fixedRate=true&period=600000&delay=0")...

但是,在使用./gradlew build fat jar 並運行為java -jar build/libs/app.jar

我在控制台收到下一個錯誤

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: timer://watchexpiration?delay=0&fixedRate=true&period=600000 due to: Error binding property (delay=0) with name: delay on bean: timer://watchexpiration?delay=0&fixedRate=true&period=600000 with value: 0
    at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:888)
    at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:777)
    at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:58)
    at org.apache.camel.reifier.AbstractReifier.resolveEndpoint(AbstractReifier.java:177)
    at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:250)
    at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:112)

但是,如果我使用./gradlew run可以正常工作 我不想為此項目使用任何框架。 我覺得這只是一個配置問題,或者我猜我的配置有問題。

我該如何解決?

build.gradle

plugins {
    id 'java'
    id 'application'
    id 'com.github.sherter.google-java-format' version '0.8'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'com.google.guava:guava:29.0-jre'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
    // Camel
    compile group: 'org.apache.camel', name: 'camel-core', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-file', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-file-watch', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-xstream', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-gson', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-rest', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-servlet', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-http', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-jackson', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-quartz', version: '3.5.0'
    compile group: 'org.apache.camel', name: 'camel-timer', version: '3.5.0'

    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'

    // Dev Libs
    compileOnly("org.projectlombok:lombok:1.18.12")
    annotationProcessor("org.projectlombok:lombok:1.18.12")

    compile group: 'org.apache.commons', name: 'commons-csv', version: '1.4'
}

application {
    mainClassName = 'com.eip.App'
}

configurations {
    // configuration that holds jars to include in the jar
    extraLibs
}

jar {
    manifest {
        attributes(
                'Main-Class': 'com.beam.agent.App'
        )
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

test {
    useJUnitPlatform()
}

googleJavaFormat {
    exclude '**/App.java'
}

跟蹤 jars 可能很棘手,因為您需要處理重復的條目。 在 Apache Camel 中有許多META-INF服務文件,這些文件正在被您簡單的jar方法覆蓋。 使用com.github.johnrengelman.shadow允許您自定義合並過程。

plugins {
    id 'java'
    id 'application'
    id 'com.github.sherter.google-java-format' version '0.8'
    id "com.github.johnrengelman.shadow" version "6.0.0" // Added plugin
}
repositories {
    jcenter()
}
dependencies {
    // ...
}
application {
    mainClassName = 'com.eip.App'
}
// Removed jar step
test {
    useJUnitPlatform()
}
googleJavaFormat {
    exclude '**/App.java'
}
// Added shadow plugin configuration
shadowJar {
    mergeServiceFiles() // Tell plugin to merge duplicate service files
    manifest {
        attributes 'Main-Class': 'com.eip.App'
    }
}
apply plugin: 'com.github.johnrengelman.shadow'

陰影可執行文件 jar 將具有后綴-all.jar

java -jar build/libs/app-all.jar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM