【发布时间】:2023-03-18 06:29:01
【问题描述】:
我在 apache karaf 上使用 osgi,我正在尝试使用 kafka 和 debezium 来运行 osgi 环境。 p>
kafka 和 debezium 还没有 osgi 准备好(karaf 不会将它们视为捆绑包),所以我确实使用 eclipse "Plug -在项目中”。我对它们进行 osgified 的 jar 如下:debezium-embedded、debezium-core、kafka connect-api、kafka connect-runtime。
一开始,当我尝试运行 debezium 时,我得到了很多“找不到类的异常”。
为了解决这个问题,我更改了两个捆绑包的清单。我向调用者添加了一个导入包,向被调用包添加了一个导出包。使用它我可以解决 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 {
}}
【问题讨论】:
-
如果您使用错误的类加载器,可能会发生错误。看起来异常发生在类监视器中。能发一下相关内容吗?
-
@ChristianSchneider 我在上面添加了代码
-
@ChristianSchneider 上面的代码在我作为独立 jar 运行时有效,但是当我尝试在 osgi karaf 上运行时出现错误
标签: osgi apache-kafka karaf debezium