noclassdeffounderror

ql3eal8s  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(322)

我正在ApacheKaraf上与osgi合作,我正在尝试使用kafka和debezium来运行osgi环境。
kafka和debezium还没有为osgi做好准备(karaf不会将它们视为bundle),所以我使用eclipse“插件项目”为它们提供了osgified。我为它们提供的jar如下:debezium embedded、debezium core、kafka connect api、kafka connect runtime。
一开始,当我尝试运行debezium时,我得到了很多“类未发现异常”。。

为了解决这个问题,我修改了两个包的清单。我向调用者添加了一个导入包,向被调用的bundle添加了一个导出包。使用这个我可以解决classnotfound问题。
在解决了所有classnotfound问题之后,我得到noclassdeffounderror

noclassdeffounderror表示类加载程序在尝试加载.class时找不到该类。。。但我确实进口了所有的包裹,也出口了。
在osgi环境中如何处理noclassdeffounderror
[编辑添加的代码]
这是班长:

public class Monitor {
    private Consumer<SourceRecord> consumer = new Consumer<SourceRecord>() {

        public void accept(SourceRecord t) {
            System.out.println("Change Detected !");
        }

    };

    public void connect() {

        System.out.println("Engine Starting");
        Configuration config = Configuration.create()
                /* begin engine properties */
                .with("connector.class", "io.debezium.connector.mysql.MySqlConnector")
                .with("offset.storage", "org.apache.kafka.connect.storage.FileOffsetBackingStore")
                .with("offset.storage.file.filename", "d:/pathTooffset.dat")
                .with("offset.flush.interval.ms", 60000)
                /* begin connector properties */
                .with("name", "my-sql-connector").with("database.hostname", "localhost").with("database.port", 3306)
                .with("database.user", "root").with("database.password", "apassword").with("server.id", 10692)
                .with("database.server.name", "localhost")
                .with("database.history", "io.debezium.relational.history.FileDatabaseHistory")
                .with("database.history.file.filename", "d:/pathTOdbhistory.dat")
                .build();
        try {
            // Create the engine with this configuration ...
            EmbeddedEngine engine = EmbeddedEngine.create().using(config).notifying(consumer).build();
            Executor executor = Executors.newFixedThreadPool(1);

            executor.execute(() -> {
                engine.run();
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

我的激活剂:

public class Activator implements BundleActivator {

public void start(BundleContext context) throws Exception {
    Monitor monitor = new Monitor();
    monitor.connect();
}

public void stop(BundleContext context) throws Exception {
}}
y3bcpkx1

y3bcpkx11#

问题一定出在嵌入式发动机内部。该错误无法初始化类意味着该类的某些静态初始化无法工作。请参阅此相关问题noclassdeffounderror无法初始化类错误。
我建议在调试模式下运行karaf,并通过这个类的初始化进行调试。

相关问题