`
wbj0110
  • 浏览: 1609453 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

利用maven创建spring-osgi powered 多bundle工程

 
阅读更多

1、创建总控pom文件添加如下内容
<?xml version="1.0" encoding="UTF-8"?>
<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>
<name>pblog</name>
<groupId>com.soho.pblog</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<description>
Centrepoint is a basic but useful application that sets up a
dashboard of project information from Maven, Archiva and
Continuum.
</description>
<properties>
<slf4j.version>1.4.3</slf4j.version>
<spring.maven.artifact.version>2.5.5</spring.maven.artifact.version>
<spring.osgi.version>1.2.1</spring.osgi.version>
<equinox.ver>3.5.1.R35x_v20090827</equinox.ver>
<equinox.services.ver>3.1.200.v20071203</equinox.services.ver>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.maven.artifact.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.maven.artifact.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.maven.artifact.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl104-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>


<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.0</version>
</dependency>

<!-- test scoped dependencies -->
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>junit.osgi</artifactId>
<version>3.8.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.maven.artifact.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-test</artifactId>
<version>${spring.osgi.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.extender</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.io</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.mock</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.web</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.web.extender</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-annotation</artifactId>
<version>${spring.osgi.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>aopalliance.osgi</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<!-- Equinox OSGi platform -->
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>${equinox.ver}</version>
<type>jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>log4j.osgi</artifactId>
<version>1.2.15-SNAPSHOT</version>
<scope>test</scope>
</dependency>

</dependencies>

<!-- for packaging as an OSGi bundle, we use the maven-bundle-plugin -->

<!--
see http://felix.apache.org/site/maven-bundle-plugin-bnd.html for more
info
-->
<build>
<resources>
<!-- standard Maven folder -->
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- plus root folder -->
<resource>
<directory>.</directory>
<includes>
<include>plugin.xml</include>
<include>META-INF/*</include>
</includes>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>1.4.3</version>
<configuration>
<manifestLocation>META-INF</manifestLocation>
<instructions>
<Export-Package>!com.soho.pbloger.impl,com.soho.pbloger*</Export-Package>
<Import-Package>*</Import-Package>
<!--
add ,plugin.xml if it's present i.e.
src/main/resources,plugin.xml
-->
<Include-Resource>src/main/resources</Include-Resource>
</instructions>
</configuration>
</plugin>

<!-- generate manifest automatically once the classes are processed -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
</configuration>
</plugin>
</plugins>
</build>

<!-- ================================================ -->
<!--            Repository Configuration              -->
<!-- ================================================ -->

<repositories>
<repository>
<id>holly-thinkpad-releases</id>
<name>holly-thinkpad-releases</name>
<url>http://localhost:8081/artifactory/repo</url>
</repository>

<!--
<repository> <id>i21-s3-osgi-repo</id> <name>i21 osgi artifacts
repo</name> <snapshots> <enabled>true</enabled> </snapshots>
<url>http://s3.amazonaws.com/maven.springframework.org/osgi</url>
</repository> <repository> <id>i21-s3-maven-repo</id> <name>i21 S3
milestone repo</name>
<url>http://s3.amazonaws.com/maven.springframework.org/milestone</url>
</repository> Spring-DM snapshot repository - disabled by default

<repository> <snapshots><enabled>true</enabled></snapshots>
<id>springframework.org</id> <name>Springframework Maven SNAPSHOT
Repository</name>
<url>http://s3.amazonaws.com/maven.springframework.org/snapshot</url>
</repository>
-->
</repositories>

<pluginRepositories>
<pluginRepository>
<id>holly-thinkpad-plugin</id>
<name>maven repo</name>
<url>http://localhost:8081/artifactory/repo</url>
</pluginRepository>

</pluginRepositories>


<modules>
<module>pblog-dal</module>
<module>pblog-biz</module>
</modules>
</project>

2、使用如下命令创建子工程

mvn archetype:generate -DartifactId=pblog-dal -DgroupId=com.soho.pblog -DarchetypeGroupId=org.springframework.osgi -DarchetypeArtifactId=spring-osgi-bundle-archetype -DarchetypeVersion=1.1.0

3、执行mvn package 生成manifest.mf
4、导入eclipse

5、注意:以上repository为本地搭建,其中用到了很多其他的repositories需要配,主要包括
http://repository.springsource.com/maven/bundles/release
http://repository.springsource.com/maven/bundles/external
http://m2.safehaus.org
http://people.apache.org/repo/m2-incubating-repository/
http://repo1.maven.org/maven2

6、最终得到的目录结构如下:
./                                                      
|-- pblog-biz                                           
|   |-- META-INF                                        
|   |   |-- MANIFEST.MF                                 
|   |   `-- readme.txt                                  
|   |-- build.properties                                
|   |-- pom.xml                                         
|   |-- readme.txt                                      
|   |-- src                                             
|   |   |-- main                                        
|   |   |   |-- java                                    
|   |   |   |   `-- com                                 
|   |   |   |       `-- soho                            
|   |   |   |           `-- pblog                       
|   |   |   |               |-- internal                
|   |   |   |               |   `-- readme.txt          
|   |   |   |               `-- readme.txt              
|   |   |   `-- resources                               
|   |   |       |-- META-INF                            
|   |   |       |   `-- spring                          
|   |   |       |       |-- bundle-context-osgi.xml     
|   |   |       |       `-- bundle-context.xml          
|   |   |       `-- log4j.properties                    
|   |   `-- test                                        
|   |       |-- java                                    
|   |       |   `-- com                                 
|   |       |       `-- soho                            
|   |       |           `-- pblog                       
|   |       |               `-- readme.txt              
|   |       `-- resources                               
|   |           `-- log4j.properties                    
|   `-- target                                          
|       |-- classes                                     
|       |   |-- META-INF                                
|       |   |   |-- MANIFEST.MF                         
|       |   |   |-- readme.txt                          
|       |   |   `-- spring                              
|       |   |       |-- bundle-context-osgi.xml         
|       |   |       `-- bundle-context.xml              
|       |   |-- com                                     
|       |   |   `-- soho                                
|       |   |       `-- pblog                           
|       |   |           `-- internal                    
|       |   `-- log4j.properties                        
|       |-- pblog-biz-1.0-SNAPSHOT.jar                  
|       `-- test-classes                                
|           |-- com                                     
|           |   `-- soho                                
|           |       `-- pblog                           
|           `-- log4j.properties                        
|-- pblog-dal                                           
|   |-- META-INF                                        
|   |   |-- MANIFEST.MF                                 
|   |   `-- readme.txt                                  
|   |-- build.properties                                
|   |-- pom.xml                                         
|   |-- readme.txt                                      
|   |-- src                                             
|   |   |-- main                                        
|   |   |   |-- java                                    
|   |   |   |   `-- com                                 
|   |   |   |       `-- soho                            
|   |   |   |           `-- pblog                       
|   |   |   |               |-- internal                
|   |   |   |               |   `-- readme.txt          
|   |   |   |               `-- readme.txt              
|   |   |   `-- resources                               
|   |   |       |-- META-INF                            
|   |   |       |   `-- spring                          
|   |   |       |       |-- bundle-context-osgi.xml     
|   |   |       |       `-- bundle-context.xml          
|   |   |       `-- log4j.properties                    
|   |   `-- test                                        
|   |       |-- java                                    
|   |       |   `-- com                                 
|   |       |       `-- soho                            
|   |       |           `-- pblog                       
|   |       |               `-- readme.txt              
|   |       `-- resources                               
|   |           `-- log4j.properties                    
|   `-- target                                          
|       |-- classes                                     
|       |   |-- META-INF                                
|       |   |   |-- MANIFEST.MF                         
|       |   |   |-- readme.txt                          
|       |   |   `-- spring                              
|       |   |       |-- bundle-context-osgi.xml
|       |   |       `-- bundle-context.xml
|       |   |-- com
|       |   |   `-- soho
|       |   |       `-- pblog
|       |   |           `-- internal
|       |   `-- log4j.properties
|       |-- pblog-dal-1.0-SNAPSHOT.jar
|       `-- test-classes
|           |-- com
|           |   `-- soho
|           |       `-- pblog
|           `-- log4j.properties
|-- pom.xml


其中参考资料为
How to create a Spring-DM bundle project using Maven Apache Felix Maven Bundle Plugin (BND)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics