我正在尝试从我的主应用程序访问OSGI Bundle。但是如果访问包中的类使用javax.xml。* package。抛出NoClassDefFoundError。
java.lang.NoClassDefFoundError: javax/xml/transform/Source
at de.foo.bar.test.Builder.<init>(Builder.java:46) ~[test-bundle-1.4.0.jar:1.4.0]
at de.foo.bar.test.request.Factory.createRequest(Factory.java:99) ~[?:?]
at de.foo.bar.test.request.Request.prepareRequest(Request.java:93) ~[?:?]
at de.foo.bar.test.request.Request.process(Request.java:60) ~[?:?]
at de.foo.bar.test.TestClass.execute(TestClass.java:74) ~[?:?]
at de.foo.bar.test.TestClass.execute(TestClass.java:1) ~[?:?]
at de.foo.bar.service.system.OsgiTransactionHandler.handleTransaction(OsgiTransactionHandler.java:71) ~[bin/:?]
at de.foo.bar.service.system.TransactionRequestService.processTransaction(TransactionRequestService.java:110) ~[bin/:?]
at de.foo.bar.service.system.TransactionRequestService.runService(TransactionRequestService.java:72) ~[bin/:?]
at de.foo.bar.service.model.InfiniteService.run(InfiniteService.java:57) ~[bin/:?]
at com.google.common.util.concurrent.AbstractExecutionThreadService$1$2.run(AbstractExecutionThreadService.java:60) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Callables$3.run(Callables.java:93) [guava-16.0.1.jar:?]
at java.lang.Thread.run(Thread.java:662) [?:1.6.0_43]
Caused by: java.lang.ClassNotFoundException: javax.xml.transform.Source not found by test-bundle [1]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532) ~[org.apache.felix.framework-4.2.1.jar:?]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75) ~[org.apache.felix.framework-4.2.1.jar:?]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955) ~[org.apache.felix.framework-4.2.1.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[?:1.6.0_43]
... 13 more
我已经检查了MANIFEST.MF中导入的包,并且可以看到包javax.xml.transform已经说明了(我已经缩短了一点):
Import-Package: com.fasterxml.jackson.core;resolution:=optional,com.fast
...
500;resolution:=optional,javax.servlet;resolution:=optional,javax.sql;r
esolution:=optional,javax.swing;resolution:=optional,javax.xml.bind;res
olution:=optional,javax.xml.bind.annotation;resolution:=optional,javax.
xml.bind.annotation.adapters;resolution:=optional,javax.xml.parsers;res
olution:=optional,javax.xml.transform;resolution:=optional,javax.xml.tr
ansform.stream;resolution:=optional,javax.xml.validation;resolution:=op
tional,org.bson;resolution:=optional,org.lightcouch;resolution:=optiona
l,org.osgi.framework;resolution:=optional;version="[1.5,2)",org.osgi.fr
amework.wiring;resolution:=optional,org.w3c.dom;resolution:=optional,or
g.xml.sax;resolution:=optional,sun.misc;resolution:=optional
我在版本4.2.1中使用apache felix作为嵌入式框架,maven-bundle-plugin配置如下:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Name>Test Bundle</Bundle-Name>
<Bundle-Activator>de.foo.bar.test.activator.TestActivator</Bundle-Activator>
<Service-Component>OSGI-INF/component.xml</Service-Component>
<Export-Package>de.foo.bar.test</Export-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*;resolution:=optional</Import-Package>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=!org.osgi.core</Embed-Dependency>
<_failok>true</_failok>
<_nouses>true</_nouses>
<_nodefaultversion>true</_nodefaultversion>
<_snapshot>${osgi-version-qualifier}</_snapshot>
</instructions>
</configuration>
</plugin>
我尝试使用FRAMEWORK_SYSTEMPACKAGES_EXTRA属性导出丢失的包。但这似乎导致导出所有Java包。我已经在第7个包裹上停止了它。
有没有办法提供这些java标准软件包而不显式导出它们?
答案 0 :(得分:0)
此问题的原因位于框架配置中。基于在线教程,我在配置中添加了以下参数:
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.5.0");
这导致默认系统包已被替换,除了我导出的额外包之外,只有org.osgi.framework可用。
在我删除此行之后,默认包再次可用,因此javax.xml.transform。