gpt4 book ai didi

java - Fat Jar中的Apache Camel Timer Nullpointer异常

转载 作者:行者123 更新时间:2023-12-03 03:53:37 25 4
gpt4 key购买 nike

我正在尝试在Gradle项目中使用Camel 3.5使用OpenJDK8作为下一个计时器

     from("timer://watchexpiration?fixedRate=true&period=600000&delay=0")...
但是,在使用 ./gradlew build构建胖 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'
}

最佳答案

阴影 jar 可能很棘手,因为您需要处理重复的条目。在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

关于java - Fat Jar中的Apache Camel Timer Nullpointer异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64015236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com