NoClassDefFoundError: OsgiDefaultCamelContext using Apache ServiceMix
NoClassDefFoundError: OsgiDefaultCamelContext using Apache ServiceMix
我创建了简单的包:
public class Activator implements BundleActivator {
private CamelContext camelContext;
private CsvDataFormat csv = new CsvDataFormat();
public void start(BundleContext bundleContext) throws Exception {
csv.setDelimiter('|');
csv.setQuoteDisabled(true);
camelContext = new OsgiDefaultCamelContext(bundleContext);
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://./in/csv?charset=windows-1251")
.unmarshal(csv)
.process(exchange -> {
//do smth
});
}
});
camelContext.start();
}
public void stop(BundleContext bundleContext) throws Exception {
camelContext.stop();
}
}
我正在使用 Apache ServiceMix
。我安装包:
karaf@root>feature:install camel-csv
karaf@root>bundle:install -s mvn:org.apache.camel/camel-core-osgi/2.16.5
但是,当我启动我的包时,出现错误:
Caused by: java.lang.NoClassDefFoundError: org/apache/camel/core/osgi/OsgiDefaultCamelContext
at ru.camel.csv.Activator.start(Activator.java:19)
但是为什么呢?在 karaf
控制台中我看到:
222 | Active | 50 | 2.16.5 | camel-csv
223 | Active | 50 | 1.1.0 | Apache Commons CSV
224 | Resolved | 80 | 1.0.0.SNAPSHOT | csv
228 | Active | 80 | 2.16.5 | camel-core-osgi
捆绑包 camel-core-osgi
包含 class OsgiDefaultCamelContext
。为什么会出现此错误?
我的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ru.camel</artifactId>
<groupId>ru.camel.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>csv</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-osgi</artifactId>
<version>2.16.5</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-csv</artifactId>
<version>2.16.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>osgi-bundle</id>
<goals>
<goal>bundle</goal>
</goals>
<phase>package</phase>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Import-Package>org.apache.camel.core.osgi.OsgiDefaultCamelContext</Import-Package>
<Bundle-Activator>ru.camel.csv.Activator</Bundle-Activator>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
您应该检查捆绑包的导入。
每个包都必须声明要导入的包 (类)。您的包可能没有声明要导入 OsgiDefaultCamelContext
所在的包。
导入是在您的包的 META-INF/MANIFEST.MF
中定义的。根据您的构建工具,此文件可能会在构建期间自动创建。否则,您必须自己编写,尽管我强烈建议您查看在构建期间自动执行此操作的工具。
在您的 pom.xml
中,将 maven-bundle-plugin
的 Import-Package
语句的配置更改为:
<Import-Package>org.apache.camel.core.osgi.*;*</Import-Package>
我创建了简单的包:
public class Activator implements BundleActivator {
private CamelContext camelContext;
private CsvDataFormat csv = new CsvDataFormat();
public void start(BundleContext bundleContext) throws Exception {
csv.setDelimiter('|');
csv.setQuoteDisabled(true);
camelContext = new OsgiDefaultCamelContext(bundleContext);
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file://./in/csv?charset=windows-1251")
.unmarshal(csv)
.process(exchange -> {
//do smth
});
}
});
camelContext.start();
}
public void stop(BundleContext bundleContext) throws Exception {
camelContext.stop();
}
}
我正在使用 Apache ServiceMix
。我安装包:
karaf@root>feature:install camel-csv
karaf@root>bundle:install -s mvn:org.apache.camel/camel-core-osgi/2.16.5
但是,当我启动我的包时,出现错误:
Caused by: java.lang.NoClassDefFoundError: org/apache/camel/core/osgi/OsgiDefaultCamelContext
at ru.camel.csv.Activator.start(Activator.java:19)
但是为什么呢?在 karaf
控制台中我看到:
222 | Active | 50 | 2.16.5 | camel-csv
223 | Active | 50 | 1.1.0 | Apache Commons CSV
224 | Resolved | 80 | 1.0.0.SNAPSHOT | csv
228 | Active | 80 | 2.16.5 | camel-core-osgi
捆绑包 camel-core-osgi
包含 class OsgiDefaultCamelContext
。为什么会出现此错误?
我的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ru.camel</artifactId>
<groupId>ru.camel.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>csv</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-osgi</artifactId>
<version>2.16.5</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-csv</artifactId>
<version>2.16.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>osgi-bundle</id>
<goals>
<goal>bundle</goal>
</goals>
<phase>package</phase>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Import-Package>org.apache.camel.core.osgi.OsgiDefaultCamelContext</Import-Package>
<Bundle-Activator>ru.camel.csv.Activator</Bundle-Activator>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
您应该检查捆绑包的导入。
每个包都必须声明要导入的包 (类)。您的包可能没有声明要导入 OsgiDefaultCamelContext
所在的包。
导入是在您的包的 META-INF/MANIFEST.MF
中定义的。根据您的构建工具,此文件可能会在构建期间自动创建。否则,您必须自己编写,尽管我强烈建议您查看在构建期间自动执行此操作的工具。
在您的 pom.xml
中,将 maven-bundle-plugin
的 Import-Package
语句的配置更改为:
<Import-Package>org.apache.camel.core.osgi.*;*</Import-Package>