Osgi 环境中的 NoClassDefFoundError

NoClassDefFoundError in Osgi environment

我在 apache karaf 上使用 osgi,我正在尝试使用 kafkadebezium 到 运行 osgi环境.

kafkadebezium 没有 osgi ready(karaf 不会将它们视为捆绑包), 所以我确实使用 eclipse "Plug-in project" 对它们进行了 osgified。我将它们 osgified 的罐子如下:debezium-embedded、debezium-core、kafka connect-api、kafka connect-运行time.

开始时,当我尝试 运行 debezium..

时,我得到了很多 "Class not found exception"

为了解决这个问题,我更改了两个包的清单。我向调用方添加了一个导入包,向被调用包添加了一个导出包。使用它我可以解决 classNotFound 问题。

解决所有 classNotfound 问题后,我得到 NoClassDefFoundError

NoClassDefFoundError 意味着 class 加载程序在尝试加载它们时找不到 .class ...但是我确实导入了所有包并也导出了它们。

关于如何在 osgi 环境

中处理 NoClassDefFoundError 的任何想法

[编辑添加代码]

这是 class 监视器:

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 {
}}

问题一定出在EmbeddedEngine. The error could not initialize class means that some static initialization of the class did not work. See this related question noclassdeffounderror-could-not-initialize-class-error

我建议运行 karaf在debug模式,通过这个class的初始化调试。