Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Fat Jar上的Apache骆驼计时器空指针异常_Java_Gradle_Timer_Apache Camel - Fatal编程技术网

Java Fat Jar上的Apache骆驼计时器空指针异常

Java Fat Jar上的Apache骆驼计时器空指针异常,java,gradle,timer,apache-camel,Java,Gradle,Timer,Apache Camel,我正试图在Gradle项目中使用Camel 3.5实现一个计时器,下一个是OpenJDK8 from("timer://watchexpiration?fixedRate=true&period=600000&delay=0")... 但是,在使用/gradlew build构建胖jar并作为java-jar build/libs/app.jar运行之后 java -jar build/libs/app-all.jar 我在控制台收到下一个错误

我正试图在Gradle项目中使用Camel 3.5实现一个计时器,下一个是OpenJDK8

     from("timer://watchexpiration?fixedRate=true&period=600000&delay=0")...
但是,在使用
/gradlew build
构建胖jar并作为
java-jar build/libs/app.jar运行之后

java -jar build/libs/app-all.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
运行,那么就像我预期的那样运行良好。 我不想在这个项目中使用任何框架。我觉得这只是一个配置问题,或者我的配置有问题

我怎样才能修好它

格雷德尔先生

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可能很棘手,因为您需要处理重复的条目。在ApacheCamel中有许多
META-INF
服务文件,这些文件正被您简单的
jar
方法覆盖。使用它可以自定义合并过程

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

谢谢你的快速回答。对不起,给你一张吉拉的票。很好!再次感谢!