Maven:未解析的对 [org.osgi.service.http] 的引用

发布于 2024-08-27 11:34:50 字数 7019 浏览 5 评论 0原文

我正在尝试使用 HttpService 创建一个包,以便使用 maven-bundle-plugin 注册 Servlet。

项目的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>felix-tutorial</groupId>
 <artifactId>example-1</artifactId>
 <version>1.0</version>
 <packaging>bundle</packaging>
 <name>Apache Felix Tutorial Example 1</name>
 <description>Apache Felix Tutorial Example 1</description>

 <!-- Build Configuration -->
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
     <instructions>
      <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
      <Bundle-Name>Service listener example</Bundle-Name>
      <Bundle-Description>A bundle that displays messages at startup and when service events occur</Bundle-Description>
      <Bundle-Vendor>Apache Felix</Bundle-Vendor>
      <Bundle-Version>1.0.0</Bundle-Version>
      <Bundle-Activator>tutorial.example1.Activator</Bundle-Activator>
      <Import-Package>org.osgi.framework;version="1.0.0", javax.servlet, javax.servlet.http</Import-Package>
     </instructions>
    </configuration>
   </plugin>
  </plugins>
 </build>

 <!-- Dependecies Management -->
 <dependencies>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.framework</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.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>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.base</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.bridge</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.bundle</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.proxy</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.whiteboard</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.osgi</groupId>
   <artifactId>osgi_R4_compendium</artifactId>
   <version>1.0</version>
  </dependency>
 </dependencies>
</project>

“mvn install”命令返回以下错误:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Felix Tutorial Example 1
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.jar

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.2/maven-install-plugin-2.2.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.2/maven-install-plugin-2.2.jar

Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.pom

Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.pom

Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.jar
Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar


[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\eclipse\ws\stripes-bundle\src\main\resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\eclipse\ws\stripes-bundle\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\eclipse\ws\stripes-bundle\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.beanopoly.stripes.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [bundle:bundle {execution: default-bundle}]
[ERROR] Error building bundle felix-tutorial:example-1:bundle:1.0 : Unresolved references to [org.osgi.service.http] by class(es) on the Bundle-Classpath[Jar:do
[ERROR] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Sat Mar 27 13:11:47 CET 2010
[INFO] Final Memory: 12M/21M
[INFO] ------------------------------------------------------------------------

I'm trying to create a bundle using HttpService for register Servlet using maven-bundle-plugin.

The pom.xml of the project is:

<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>felix-tutorial</groupId>
 <artifactId>example-1</artifactId>
 <version>1.0</version>
 <packaging>bundle</packaging>
 <name>Apache Felix Tutorial Example 1</name>
 <description>Apache Felix Tutorial Example 1</description>

 <!-- Build Configuration -->
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
     <instructions>
      <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
      <Bundle-Name>Service listener example</Bundle-Name>
      <Bundle-Description>A bundle that displays messages at startup and when service events occur</Bundle-Description>
      <Bundle-Vendor>Apache Felix</Bundle-Vendor>
      <Bundle-Version>1.0.0</Bundle-Version>
      <Bundle-Activator>tutorial.example1.Activator</Bundle-Activator>
      <Import-Package>org.osgi.framework;version="1.0.0", javax.servlet, javax.servlet.http</Import-Package>
     </instructions>
    </configuration>
   </plugin>
  </plugins>
 </build>

 <!-- Dependecies Management -->
 <dependencies>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.framework</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.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>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.base</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.bridge</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.bundle</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.proxy</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.http.whiteboard</artifactId>
   <version>2.0.4</version>
  </dependency>
  <dependency>
   <groupId>org.osgi</groupId>
   <artifactId>osgi_R4_compendium</artifactId>
   <version>1.0</version>
  </dependency>
 </dependencies>
</project>

"mvn install" command returns the following error:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Felix Tutorial Example 1
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.jar

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.2/maven-install-plugin-2.2.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.2/maven-install-plugin-2.2.jar

Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.pom

Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.pom

Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-interpolation/1.6/plexus-interpolation-1.6.jar
Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar


[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\eclipse\ws\stripes-bundle\src\main\resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\eclipse\ws\stripes-bundle\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\eclipse\ws\stripes-bundle\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.beanopoly.stripes.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [bundle:bundle {execution: default-bundle}]
[ERROR] Error building bundle felix-tutorial:example-1:bundle:1.0 : Unresolved references to [org.osgi.service.http] by class(es) on the Bundle-Classpath[Jar:do
[ERROR] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Sat Mar 27 13:11:47 CET 2010
[INFO] Final Memory: 12M/21M
[INFO] ------------------------------------------------------------------------

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南烟 2024-09-03 11:34:50

在 maven-bundle-plugin 的配置中,您必须指定需要导入的所有包。

在你的情况下应该是:

   <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
     <instructions>
      ...
      <Import-Package>org.osgi.service.http, org.osgi.framework;version="1.0.0", javax.servlet, javax.servlet.http</Import-Package>
     </instructions>
    </configuration>
   </plugin>

In the configuration of the maven-bundle-plugin you have to specify all the packages you need to import.

In your case it should be:

   <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
     <instructions>
      ...
      <Import-Package>org.osgi.service.http, org.osgi.framework;version="1.0.0", javax.servlet, javax.servlet.http</Import-Package>
     </instructions>
    </configuration>
   </plugin>
﹎☆浅夏丿初晴 2024-09-03 11:34:50

给出的答案是错误的。您无需指定需要导入的所有包。只需在指令末尾添加一个 * 即可导入(没有版本定义)缺少的包:

<Import-Package>org.osgi.framework;version="1.0.0", javax.servlet, javax.servlet.http**,***</Import-Package>

The given answer is wrong. You don't need to specify ALL the packages you need to import. Simply put a * at the end of your instruction to import (without version definition) the missing packages:

<Import-Package>org.osgi.framework;version="1.0.0", javax.servlet, javax.servlet.http**,***</Import-Package>
梦萦几度 2024-09-03 11:34:50

使用较新的捆绑版本:
org.apache.felix
maven 捆绑插件
2.0.0
真的

Use the newer bundle version:
org.apache.felix
maven-bundle-plugin
2.0.0
true

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文