Groovy脚本没有在Camel(Project)中执行



场景:只想将文件从一个位置传输到另一个位置使用camel和groovy脚本定位

问题:我没有在控制台中看到任何错误,但我们如何才能确保脚本正在执行。

示例MainApp程序:

class MainApp {

static void main(String... args)  {
def camelContext = new DefaultCamelContext()
println("printing something in the console MainApp")
camelContext.addRoutes( new RouteBuilder() {
@Override
void configure() {
println("Printing some thing before queue")
from("Test").to("Test")
println("printing something after queue")
}
})
//camelContext.start()
// Thread.sleep(10000)
// camelContext.stop()
}
}

Output :
sampling ...
include patterns:
org.apache.camel..*
exclude patterns:
printing something in the console MainApp
Printing some thing before queue
printing something after queue
Process finished with exit code 0

Pom.xml文件:若您可以观察到,下面的文件包含所有与groovy和camel相关的jar文件。。(我认为pom文件有问题。如果你发现了同样的问题,请告诉我(

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>SampleCamelProject</groupId>
<artifactId>camel-example-groovy</artifactId>
<packaging>jar</packaging>
<version>0.0.0</version>
<name>SampleCamelProject</name>
<properties>
<maven-compiler-plugin-version>3.8.0</maven-compiler-plugin-version>
<maven-resources-plugin-version>3.1.0</maven-resources-plugin-version>
<maven-eclipse-plugin-version>2.10</maven-eclipse-plugin-version>
<exec-maven-plugin-version>1.6.0</exec-maven-plugin-version>

<camel-core-version>2.13.3</camel-core-version>
<camel-groovy-dsl-version>2.19.5</camel-groovy-dsl-version>
<camel-jetty-version>1.6.0</camel-jetty-version>
<log4j-api-version>2.11.1</log4j-api-version>
<log4j-core-version>2.11.1</log4j-core-version>
<log4j-slf4j-version>2.11.1</log4j-slf4j-version>
</properties>

<description>A Camel route using Groovy DSL</description>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-core-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-groovy-dsl</artifactId>
<version>${camel-groovy-dsl-version}</version>
</dependency>
<!-- used for jetty -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>${camel-jetty-version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-api-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-core-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j-slf4j-version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin-version}</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<!-- <verbose>true</verbose> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${maven-eclipse-plugin-version}</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
<!-- Allows the example to be run via 'mvn compile exec:java' -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin-version}</version>
<configuration>
<mainClass>org.apache.camel.MainAppTest</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk9-build</id>
<activation>
<jdk>9</jdk>
</activation>
<build>
<plugins>
<plugin>
<!--Skip compile on Java 9 https://issues.apache.org/jira/browse/CAMEL-10905 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

上面是我在java中执行的同一个应用程序:我得到了一个错误(正如预期的那样(

由以下原因引起:org.apache.camel.FailedToCreateRouteException:未能创建路由route1:路由(route1([[From[Test]]->[To[Test]],因为找不到的终结点:Test,请检查您的类路径包含所需的Camel组件jar。

我对groovy脚本的期望也是一样的。。如果我错过了什么。

我给自己一个以上问题的答案。我还没有想过执行一种简单的编写Groovy脚本的方法。我已经尝试了下面的代码,它正在工作。

package org.apache.camel
import org.apache.camel.impl.*
import org.apache.camel.builder.*
def camelContext = new DefaultCamelContext()
camelContext.addRoutes(new RouteBuilder() {
def void configure() {
from("Test")
.to("Test")
}
})
camelContext.start()
addShutdownHook{ camelContext.stop() }
synchronized(this){ this.wait() }

也许我们可以用groovy脚本执行上面发布的问题。。但当出现错误时,我没有看到任何控制台日志。请就这件事向我提出建议。。我真的很想知道这个过程是如何执行的。。非常感谢提前。

相关内容

最新更新