0

統合の目的で apache camel を起動しようとしています。このクラスを実行する camel 構成のために何をする必要があるか教えてください。

クラス実行エラー

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.apache.camel.support.ServiceSupport.<clinit>(ServiceSupport.java:39)
    at MainExample.boot(MainExample.java:21)
    at MainExample.main(MainExample.java:16)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more

そして、camel-core-2.11.0.jar を使用します

これが私のカルスです

MainExample.java

import java.util.Date;

import javax.annotation.processing.Processor;

import org.apache.camel.Exchange;
import org.apache.camel.Main;
import org.apache.camel.builder.RouteBuilder;

@SuppressWarnings("deprecation")
public class MainExample {

    private Main main;

    public static void main(String[] args) throws Exception {
        MainExample example = new MainExample();
        example.boot();
    }

    public void boot() throws Exception {
        // create a Main instance
        main = new Main();
        // enable hangup support so you can press ctrl + c to terminate the JVM
        main.enableHangupSupport();
        // bind MyBean into the registery
        main.bind("foo", new MyBean());
        // add routes
        main.addRouteBuilder(new MyRouteBuilder());

        // run until you terminate the JVM
        System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
        main.run();
    }

    private static class MyRouteBuilder extends RouteBuilder {
        @Override
        public void configure() throws Exception {
            from("timer:foo?delay=2000")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("Invoked timer at " + new Date());
                    }
                })
                .beanRef("foo");
        }
    }

    public static class MyBean {
        public void callMe() {
            System.out.println("MyBean.calleMe method has been called");
        }
    }
}
4

1 に答える 1

0

SLF4J ライブラリを CLASSPATH に追加するだけです。通常、SLF4J API (slf4j-api-version.jar) と 1 つの実装 (slf4j-log4j-version.jar など) が必要です。

于 2013-04-26T07:53:01.957 に答える