2012-04-03 75 views
3

我正在使用maven-bundle-plugin构建一个war文件作为我想在Felix中部署的一个包。这是POM文件。在Felix.missing要求[5.0]中启动包的问题osgi.wiring.package; (osgi.wiring.package = com.sun.jersey.api.core)

<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"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>net.java</groupId> 
    <artifactId>jvnet-parent</artifactId> 
    <version>1</version> 
</parent> 
<groupId>com.sun.jersey.samples.helloworld-osgi-webapp</groupId> 
<artifactId>war-bundle</artifactId> 
<version>1.11</version> 
<name>Helloworld OSGi WebApp - Jersey Sample WAR</name> 
<packaging>war</packaging> 
<dependencies> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <!-- <scope>provided</scope> --> 
    </dependency> 
    <dependency> 
     <groupId>org.osgi</groupId> 
     <artifactId>org.osgi.core</artifactId> 
     <version>4.2.0</version> 
     <!-- <scope>provided</scope> --> 
    </dependency> 
    <dependency> 
     <groupId>org.osgi</groupId> 
     <artifactId>org.osgi.compendium</artifactId> 
     <version>4.2.0</version> 
     <!-- <scope>provided</scope> --> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-core</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.jettison</groupId> 
     <artifactId>jettison</artifactId> 
     <version>1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-core-asl</artifactId> 
     <version>1.5.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-mapper-asl</artifactId> 
     <version>1.5.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-jaxrs</artifactId> 
     <version>1.5.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-xc</artifactId> 
     <version>1.5.5</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.http.api</artifactId> 
     <version>2.0.4</version> 
    </dependency> 

</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <inherited>true</inherited> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 

     <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> 
       </execution> 
      </executions> 
      <configuration> 
       <manifestLocation>${project.build.directory}/META-INF</manifestLocation> 
       <supportedProjectTypes> 
        <supportedProjectType>bundle</supportedProjectType> 
        <supportedProjectType>war</supportedProjectType> 
       </supportedProjectTypes> 
       <instructions> 
        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> 
        <Import-Package>com.sun.jersey.api.core,com.sun.jersey.spi.container.servlet,*</Import-Package> 
        <Export-Package>com.sun.jersey.samples.helloworld</Export-Package> 
        <Webapp-Context>jersyweb</Webapp-Context> 
        <Web-ContextPath>jersyweb</Web-ContextPath> 
        <Bundle-Activator>com.sun.jersey.samples.helloworld.WebAppContextListener</Bundle-Activator> 
        <Bundle-ClassPath>WEB-INF/classes</Bundle-ClassPath> 
        <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency> 
        <Embed-Transitive>true</Embed-Transitive> 
       </instructions> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1-alpha-2</version> 
      <configuration> 
       <attachClasses>true</attachClasses> 
       <archive> 
        <manifestFile>${project.build.directory}/META-INF/MANIFEST.MF</manifestFile> 
        <manifestEntries> 
         <Bundle-ClassPath>WEB-INF/classes</Bundle-ClassPath> 
        </manifestEntries> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
    <pluginManagement> 
     <plugins> 
      <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId> 
             org.apache.felix 
            </groupId> 
            <artifactId> 
             maven-bundle-plugin 
            </artifactId> 
            <versionRange> 
             [2.0.1,) 
            </versionRange> 
            <goals> 
             <goal>manifest</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore></ignore> 
           </action> 
          </pluginExecution> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId> 
             org.jvnet.jaxb2.maven2 
            </groupId> 
            <artifactId> 
             maven-jaxb2-plugin 
            </artifactId> 
            <versionRange> 
             [0.8.1,) 
            </versionRange> 
            <goals> 
             <goal>generate</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore></ignore> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

当我把它使用maven安装搭建,我可以看到在战争中捆绑的META-INF文件夹中的逻辑正确的MANIFEST.MF文件。这里是MANIFEST.MF。

**Manifest-Version: 1.0 
Archiver-Version: Plexus Archiver 
Created-By: Apache Maven Bundle Plugin 
Built-By: parag.ki 
Build-Jdk: 1.6.0_18 
Bundle-ClassPath: WEB-INF/classes,servlet-api-2.5.jar,org.osgi.core-4. 
2.0.jar,org.osgi.compendium-4.2.0.jar,jersey-core-1.11.jar,jersey-ser 
ver-1.11.jar,asm-3.1.jar,jettison-1.1.jar,stax-api-1.0.1.jar,jackson- 
core-asl-1.5.5.jar,jackson-mapper-asl-1.5.5.jar,jackson-jaxrs-1.5.5.j 
ar,jackson-xc-1.5.5.jar,org.apache.felix.http.api-2.0.4.jar 
Bnd-LastModified: 1333436962460 
Bundle-Activator: com.sun.jersey.samples.helloworld.WebAppContextListe 
ner 
Bundle-Description: Java.net - The Source for Java Technology Collabor 
ation 
Bundle-ManifestVersion: 2 
Bundle-Name: Helloworld OSGi WebApp - Jersey Sample WAR 
Bundle-SymbolicName: war-bundle 
Bundle-Version: 1.11.0 
Embed-Dependency: *;scope=compile|runtime;inline=false 
Embed-Transitive: true 
Embedded-Artifacts: servlet-api-2.5.jar;g="javax.servlet";a="servlet-a 
pi";v="2.5",org.osgi.core-4.2.0.jar;g="org.osgi";a="org.osgi.core";v= 
"4.2.0",org.osgi.compendium-4.2.0.jar;g="org.osgi";a="org.osgi.compen 
dium";v="4.2.0",jersey-core-1.11.jar;g="com.sun.jersey";a="jersey-cor 
e";v="1.11",jersey-server-1.11.jar;g="com.sun.jersey";a="jersey-serve 
r";v="1.11",asm-3.1.jar;g="asm";a="asm";v="3.1",jettison-1.1.jar;g="o 
rg.codehaus.jettison";a="jettison";v="1.1",stax-api-1.0.1.jar;g="stax 
";a="stax-api";v="1.0.1",jackson-core-asl-1.5.5.jar;g="org.codehaus.j 
ackson";a="jackson-core-asl";v="1.5.5",jackson-mapper-asl-1.5.5.jar;g 
="org.codehaus.jackson";a="jackson-mapper-asl";v="1.5.5",jackson-jaxr 
s-1.5.5.jar;g="org.codehaus.jackson";a="jackson-jaxrs";v="1.5.5",jack 
son-xc-1.5.5.jar;g="org.codehaus.jackson";a="jackson-xc";v="1.5.5",or 
g.apache.felix.http.api-2.0.4.jar;g="org.apache.felix";a="org.apache. 
felix.http.api";v="2.0.4" 
Import-Package: com.sun.jersey.api.core,com.sun.jersey.samples.hellowo 
rld,com.sun.jersey.spi.container.servlet,com.sun.net.httpserver,javax 
.activation,javax.annotation.security,javax.imageio,javax.imageio.spi 
,javax.imageio.stream,javax.mail,javax.mail.internet,javax.mail.util, 
javax.microedition.io,javax.naming,javax.security.auth.x500,javax.xml 
.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.adapters,ja 
vax.xml.datatype,javax.xml.parsers,javax.xml.transform,javax.xml.tran 
sform.dom,javax.xml.transform.sax,javax.xml.transform.stream,org.joda 
.time,org.joda.time.format,org.w3c.dom,org.w3c.dom.bootstrap,org.w3c. 
dom.ls,org.xml.sax 
Tool: Bnd-1.50.0 
Web-ContextPath: jersyweb 
Webapp-Context: jersyweb** 

但是,当我将它部署在Apache Felix中并启动它时,我看到以下错误。

g! org.osgi.framework.BundleException:bundle war-bundle中的未解决约束[5]:无法解析5.0:缺少需求[5.0] osgi.wiring.package; (osgi.wiring.package = com.sun.jersey.api.core)

包com.sun.jersey.api.core是jersey-core-1.11.jar的一部分,它已经在Bundle- MANIFEST.MF中的ClassPath,那我为什么会得到这个错误?

如果我开始为jersey-core-1.11.jar分别打包捆绑文件,那么问题就解决了,但我不认为它是一个很好的解决方案。实际上为此目的只提供maven bundle插件和标签。

请指教。

+2

我看到这个问题已经有一段时间没有答案了,所以你可能已经移动了。 仍然,作为提示:添加更多标签。你只是把它标记为apache-felix,而我(和我怀疑许多人)只是跟踪OSGi的问题,无论如何它几乎包括所有的Felix问题。 如果你这样做了,你会在两个小时而不是两个月内得到答案。为了将来的参考,我已经添加了标签。 – 2012-06-12 13:46:38

回答

4

快速查看MANIFEST文件,我看到有 com.sun.jersey.api.core的导入包。我认为你也嵌入了这个包,但是这对这个依赖没有影响。如果你要求依赖,你会得到它

只需删除它应该工作,在maven中,你可以从Import-Package行中删除它。

此外,你确实嵌入了很多。我认为将servlet api嵌入到webapp中并不是一个好主意,因为应用程序服务器提供了该API。它可能工作,但在部署到其他应用程序服务器时可能会遇到麻烦。

相关问题