我写了一个简单的平针织webservice(基于servlet的WAR)来OSGIfied并部署到karaf中。应用程序使用eclipse编写,并作为maven web项目编写,旨在部署为WAR。编译&正确安装,生成战争没有任何错误。文件内容如下: -
请不要将此作为副本记录到其他类似的问题,因为我检查了这些并尝试应用那里给出的一些解决方案(不成功)
的pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ione</groupId>
<artifactId>karaftest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>karaftest Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>karaftest</finalName>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Bundle-SymbolicName>karaftest</Bundle-SymbolicName>
<Export-Package/>
<Import-Package/>
<Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Web-ContextPath>karaftest</Web-ContextPath>
<Webapp-Context>karaftest</Webapp-Context>
</instructions>
</configuration>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<!-- ... etc ... -->
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Karaf stuff OSGIfy the WAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<!-- OSGIfication -->
</plugins>
</build>
如您所见,我只声明了两个依赖项(其中log4j在提供的范围内)
生成的MANIFEST.MF
Manifest-Version: 1.0
Bnd-LastModified: 1455060085036
Build-Jdk: 1.8.0_45
Built-By: nish
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib/jersey-container-servlet
-2.22.1.jar,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar,WEB-IN
F/lib/javax.inject-2.4.0-b31.jar,WEB-INF/lib/jersey-common-2.22.1.jar,W
EB-INF/lib/javax.annotation-api-1.2.jar,WEB-INF/lib/jersey-guava-2.22.1
.jar,WEB-INF/lib/hk2-api-2.4.0-b31.jar,WEB-INF/lib/hk2-utils-2.4.0-b31.
jar,WEB-INF/lib/aopalliance-repackaged-2.4.0-b31.jar,WEB-INF/lib/hk2-lo
cator-2.4.0-b31.jar,WEB-INF/lib/javassist-3.18.1-GA.jar,WEB-INF/lib/osg
i-resource-locator-1.0.1.jar,WEB-INF/lib/jersey-server-2.22.1.jar,WEB-I
NF/lib/jersey-client-2.22.1.jar,WEB-INF/lib/jersey-media-jaxb-2.22.1.ja
r,WEB-INF/lib/validation-api-1.1.0.Final.jar,WEB-INF/lib/javax.ws.rs-ap
i-2.0.1.jar
Bundle-ManifestVersion: 2
Bundle-Name: karaftest Maven Webapp
Bundle-SymbolicName: karaftest
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=compile|runtime
Embed-Directory: WEB-INF/lib
Embed-Transitive: true
Embedded-Artifacts: WEB-INF/lib/jersey-container-servlet-2.22.1.jar;g="o
rg.glassfish.jersey.containers";a="jersey-container-servlet";v="2.22.1"
,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar;g="org.glassfish.
jersey.containers";a="jersey-container-servlet-core";v="2.22.1",WEB-INF
/lib/javax.inject-2.4.0-b31.jar;g="org.glassfish.hk2.external";a="javax
.inject";v="2.4.0-b31",WEB-INF/lib/jersey-common-2.22.1.jar;g="org.glas
sfish.jersey.core";a="jersey-common";v="2.22.1",WEB-INF/lib/javax.annot
ation-api-1.2.jar;g="javax.annotation";a="javax.annotation-api";v="1.2"
,WEB-INF/lib/jersey-guava-2.22.1.jar;g="org.glassfish.jersey.bundles.re
packaged";a="jersey-guava";v="2.22.1",WEB-INF/lib/hk2-api-2.4.0-b31.jar
;g="org.glassfish.hk2";a="hk2-api";v="2.4.0-b31",WEB-INF/lib/hk2-utils-
2.4.0-b31.jar;g="org.glassfish.hk2";a="hk2-utils";v="2.4.0-b31",WEB-INF
/lib/aopalliance-repackaged-2.4.0-b31.jar;g="org.glassfish.hk2.external
";a="aopalliance-repackaged";v="2.4.0-b31",WEB-INF/lib/hk2-locator-2.4.
0-b31.jar;g="org.glassfish.hk2";a="hk2-locator";v="2.4.0-b31",WEB-INF/l
ib/javassist-3.18.1-GA.jar;g="org.javassist";a="javassist";v="3.18.1-GA
",WEB-INF/lib/osgi-resource-locator-1.0.1.jar;g="org.glassfish.hk2";a="
osgi-resource-locator";v="1.0.1",WEB-INF/lib/jersey-server-2.22.1.jar;g
="org.glassfish.jersey.core";a="jersey-server";v="2.22.1",WEB-INF/lib/j
ersey-client-2.22.1.jar;g="org.glassfish.jersey.core";a="jersey-client"
;v="2.22.1",WEB-INF/lib/jersey-media-jaxb-2.22.1.jar;g="org.glassfish.j
ersey.media";a="jersey-media-jaxb";v="2.22.1",WEB-INF/lib/validation-ap
i-1.1.0.Final.jar;g="javax.validation";a="validation-api";v="1.1.0.Fina
l",WEB-INF/lib/javax.ws.rs-api-2.0.1.jar;g="javax.ws.rs";a="javax.ws.rs
-api";v="2.0.1"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-3.0.0.201509101326
Web-ContextPath: karaftest
Webapp-Context: karaftest
我按照说明将生成的WAR复制到karaf / deploy文件夹并运行karaf.bar服务器。它不断抛出错误
karaf.bat: Ignoring predefined value for KARAF_HOME
ERROR: Bundle karaftest [139] Error starting file:/C:/Essentials/iONE/apache-kar
af-3.0.3/apache-karaf-3.0.3/deploy/karaftest.war (org.osgi.framework.BundleExcep
tion: Unresolved constraint in bundle karaftest [139]: Unable to resolve 139.0:
missing requirement [139.0] osgi.wiring.package; (osgi.wiring.package=com.sun.jd
i))
org.osgi.framework.BundleException: Unresolved constraint in bundle karaftest [1
39]: Unable to resolve 139.0: missing requirement [139.0] osgi.wiring.package; (
osgi.wiring.package=com.sun.jdi)
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:397
4)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStart
LevelImpl.java:304)
at java.lang.Thread.run(Thread.java:745)
我不知道它试图解决com.sun.jdi的位置。据我所知,它是一个特定于专有sun类的包。我试图解决这个问题并且不成功的事情
我是OSGI宇宙的新手(就像一天),所以我不确定为什么部署一个简单的WAR这么难。此外,我不知道它从我的应用程序WAR获取与com.sun.jdi相关的信息。我怀疑它是否是作为球衣的一部分解决的任何罐子的传递依赖罐。
非常感谢任何帮助(如果您在海湾地区,请使用啤酒)。感谢
更新
通过将POM.XML更改为import-packages来更新MANIFEST.MF。在部署到karaf作为WAR时仍然会遇到相同的异常。在manifest.mf中可以看到com.sun.jdi正在导入。
更新MANIFEST.MF
Manifest-Version: 1.0
Bnd-LastModified: 1455065767920
Build-Jdk: 1.8.0_45
Built-By: nish
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib/jersey-container-servlet
-2.22.1.jar,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar,WEB-IN
F/lib/javax.inject-2.4.0-b31.jar,WEB-INF/lib/jersey-common-2.22.1.jar,W
EB-INF/lib/javax.annotation-api-1.2.jar,WEB-INF/lib/jersey-guava-2.22.1
.jar,WEB-INF/lib/hk2-api-2.4.0-b31.jar,WEB-INF/lib/hk2-utils-2.4.0-b31.
jar,WEB-INF/lib/aopalliance-repackaged-2.4.0-b31.jar,WEB-INF/lib/hk2-lo
cator-2.4.0-b31.jar,WEB-INF/lib/javassist-3.18.1-GA.jar,WEB-INF/lib/osg
i-resource-locator-1.0.1.jar,WEB-INF/lib/jersey-server-2.22.1.jar,WEB-I
NF/lib/jersey-client-2.22.1.jar,WEB-INF/lib/jersey-media-jaxb-2.22.1.ja
r,WEB-INF/lib/validation-api-1.1.0.Final.jar,WEB-INF/lib/javax.ws.rs-ap
i-2.0.1.jar
Bundle-ManifestVersion: 2
Bundle-Name: karaftest Maven Webapp
Bundle-SymbolicName: karaftest
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=compile|runtime
Embed-Directory: WEB-INF/lib
Embed-Transitive: true
Embedded-Artifacts: WEB-INF/lib/jersey-container-servlet-2.22.1.jar;g="o
rg.glassfish.jersey.containers";a="jersey-container-servlet";v="2.22.1"
,WEB-INF/lib/jersey-container-servlet-core-2.22.1.jar;g="org.glassfish.
jersey.containers";a="jersey-container-servlet-core";v="2.22.1",WEB-INF
/lib/javax.inject-2.4.0-b31.jar;g="org.glassfish.hk2.external";a="javax
.inject";v="2.4.0-b31",WEB-INF/lib/jersey-common-2.22.1.jar;g="org.glas
sfish.jersey.core";a="jersey-common";v="2.22.1",WEB-INF/lib/javax.annot
ation-api-1.2.jar;g="javax.annotation";a="javax.annotation-api";v="1.2"
,WEB-INF/lib/jersey-guava-2.22.1.jar;g="org.glassfish.jersey.bundles.re
packaged";a="jersey-guava";v="2.22.1",WEB-INF/lib/hk2-api-2.4.0-b31.jar
;g="org.glassfish.hk2";a="hk2-api";v="2.4.0-b31",WEB-INF/lib/hk2-utils-
2.4.0-b31.jar;g="org.glassfish.hk2";a="hk2-utils";v="2.4.0-b31",WEB-INF
/lib/aopalliance-repackaged-2.4.0-b31.jar;g="org.glassfish.hk2.external
";a="aopalliance-repackaged";v="2.4.0-b31",WEB-INF/lib/hk2-locator-2.4.
0-b31.jar;g="org.glassfish.hk2";a="hk2-locator";v="2.4.0-b31",WEB-INF/l
ib/javassist-3.18.1-GA.jar;g="org.javassist";a="javassist";v="3.18.1-GA
",WEB-INF/lib/osgi-resource-locator-1.0.1.jar;g="org.glassfish.hk2";a="
osgi-resource-locator";v="1.0.1",WEB-INF/lib/jersey-server-2.22.1.jar;g
="org.glassfish.jersey.core";a="jersey-server";v="2.22.1",WEB-INF/lib/j
ersey-client-2.22.1.jar;g="org.glassfish.jersey.core";a="jersey-client"
;v="2.22.1",WEB-INF/lib/jersey-media-jaxb-2.22.1.jar;g="org.glassfish.j
ersey.media";a="jersey-media-jaxb";v="2.22.1",WEB-INF/lib/validation-ap
i-1.1.0.Final.jar;g="javax.validation";a="validation-api";v="1.1.0.Fina
l",WEB-INF/lib/javax.ws.rs-api-2.0.1.jar;g="javax.ws.rs";a="javax.ws.rs
-api";v="2.0.1"
Import-Package: com.sun.jdi,com.sun.jdi.connect,com.sun.jdi.event,com.su
n.jdi.request,javax.activation,javax.imageio,javax.imageio.spi,javax.im
ageio.stream,javax.jws,javax.management,javax.naming,javax.net.ssl,java
x.persistence,javax.servlet,javax.servlet.annotation,javax.servlet.http
,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.ada
pters,javax.xml.datatype,javax.xml.namespace,javax.xml.parsers,javax.xm
l.stream,javax.xml.transform,javax.xml.transform.dom,javax.xml.transfor
m.sax,javax.xml.transform.stream,javax.xml.validation,javax.xml.ws,jers
ey.repackaged.com.google.common.cache.LocalCache.jersey.repackaged.com.
google.common.cache,jersey.repackaged.com.google.common.cache.LocalCach
e.jersey.repackaged.com.google.common.cache.LocalCache$jersey.repackage
d.com.google.common.cache,jersey.repackaged.com.google.common.collect.A
bstractMapBasedMultimap.jersey.repackaged.com.google.common.collect,jer
sey.repackaged.com.google.common.collect.AbstractMapBasedMultimap.jerse
y.repackaged.com.google.common.collect.AbstractMapBasedMultimap$Wrapped
Collection.jersey.repackaged.com.google.common.collect,jersey.repackage
d.com.google.common.collect.AbstractMultimap.jersey.repackaged.com.goog
le.common.collect,jersey.repackaged.com.google.common.collect.FilteredK
eyMultimap.jersey.repackaged.com.google.common.collect,jersey.repackage
d.com.google.common.collect.ImmutableMultimap.jersey.repackaged.com.goo
gle.common.collect,jersey.repackaged.com.google.common.collect.MapMaker
InternalMap.jersey.repackaged.com.google.common.collect,jersey.repackag
ed.com.google.common.collect.MapMakerInternalMap.jersey.repackaged.com.
google.common.collect.MapMakerInternalMap$jersey.repackaged.com.google.
common.collect,jersey.repackaged.com.google.common.collect.Maps$Filtere
dEntryMap.jersey.repackaged.com.google.common.collect,jersey.repackaged
.com.google.common.collect.StandardTable.jersey.repackaged.com.google.c
ommon.collect,org.apache.log4j;version="[1.2,2)",org.osgi.framework,org
.w3c.dom,org.xml.sax,org.xml.sax.helpers,sun.misc
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-3.0.0.201509101326
Web-ContextPath: karaftest
Webapp-Context: karaftest