---
title: "OSGI注意细节"
author: "fengzl"
date: "2008-12-05T10:24:02Z"
tags: []
slug: "osgi"
draft: false
lastmod: "2008-12-13T13:54:19Z"
id: 287285
url: "https://fengzl.iteye.com/blog/287285"
---

关于第三方包地加入

eclipse: New-> Other -> Plug-in from existing JAR archives

导入到当前工程中

或者放在MANIFEST.MF的 Bundle-ClassPath: .,下，不过这样会造成jar打包时候有问题

最好的办法：建立一个bundle，让他的Bundle-ClassPath 加入全部的jar为其他的bundle提供服务 

spring osgi bundle update操作并不管什么用，需要refresh操作

创建bundle最好的办法是:



下载，http://maven.apache.org/

环境变量 ，添加 MAVEN_HOME : D:\java\apache-maven-2.0.9\,

在path中加入D:\java\apache-maven-2.0.9\bin

如果安装老是失败，建议用 mvn clean install,

如果出现下面的错误，可以忽略
 BUILD ERROR
 ————————————————————————
 Cannot execute mojo: clean. It requires a project with an existing pom.xm
l, but the build is not using one.

新建一个空的目录，如D:\test\osgi，打开cmd并到刚才建的目录下执行：

mvn archetype:create   -DarchetypeGroupId=org.springframework.osgi -DarchetypeArtifactId=spring-osgi-bundle-archetype  -DarchetypeVersion=1.1.0   -DgroupId=org.foo  -DartifactId=org.foo.my-springdm-bundle -Dversion=0.1

注意是这一行命令, 项目框架用的是spring-osgi-bundle-archetype,如果看到一个新建目录org.foo.my-springdm-bundle，表示已经建好了一个空项目 ：-）。

进入项目的根目录,用下面的命令生成MANIFEST.MF file 和 META-INF目录。

cd D:\test\osgi\org.foo.my-springdm-bundle

mvn package
mvn org.apache.felix:maven-bundle-plugin:manifest

最后的生成结果

    * Packaged as an OSGi bundle
    * META-INF/MANIFEST.MF automatically generated
    * src/main/java/<package> public package automatically exported
    * src/main/java/<package>/internal private package
    * src/main/resources/META-INF/spring/bundle-context.xml is a spring configuration file that defines the simple bean.
    * src/main/resources/META-INF/spring/bundle-context-osgi.xml is a spring configuration file ready for you to add bean definitions from the osgi namespace (services, references etc.).
    * .project, .classpath, and build.properties files created to enable use of this project directly inside eclipse as a PDE plugin project