SpringDM笔记2-SpringDM版HelloWorld
1. 构建运行目录
??? (1)创建SpringDM-HelloWorld文件夹,解压spring-osgi-2.0.0.M1-with-dependencies.zip,复制lib目录下的
??? org.eclipse.osgi-3.5.1.R35x_v20090827.jar至SpringDM - 的HelloWorld下,测试:
??? java -jar org.eclipse.osgi-3.5.1.R35x_v20090827.jar -console
??? 执行该命令后在SpringDM - 的HelloWorld 文件夹下生成configuration文件夹。在configuration文件夹下创建
??? (2)创建config.ini文件
??? 在configuration文件夹下创建config.ini文件:
osgi.bundles=bundles/org.springframework.aop-3.0.0.RC1.jar@start, \
bundles/org.springframework.asm-3.0.0.RC1.jar@start, \
bundles/org.springframework.beans-3.0.0.RC1.jar@start, \
bundles/org.springframework.context-3.0.0.RC1.jar@start, \
bundles/org.springframework.core-3.0.0.RC1.jar@start, \
bundles/org.springframework.expression-3.0.0.RC1.jar@start, \
bundles/spring-osgi-core-2.0.0.M1.jar@start, \
bundles/spring-osgi-extender-2.0.0.M1.jar@start, \
bundles/spring-osgi-io-2.0.0.M1.jar@start, \
bundles/com.springsource.org.aopalliance-1.0.0.jar@start, \
bundles/com.springsource.slf4j.api-1.5.6.jar@start, \
bundles/com.springsource.slf4j.nop-1.6.1.jar, \
bundles/com.springsource.slf4j.org.apache.commons.logging-1.5.6.jar@start
???? (3) 创建bundles目录
????? 复制lib目录下的相关JAR文件至该目录下,即上面cinfig.ini文件中的JAR文件,其中com.springsource.slf4j
????? .nop-1.6.1.jar需至SSOBR上下载。
????? 检测新增加的JAR是否启动,命令:ss
???? (4) 创建SRC目录
???? 在该目录下新建类:HelloWorld.java:
???? package com.manning.sdmia;
???? public class HelloWorld {
?????????? public void start() throws Exception {
??? ??????????? System.out.println("Hello Spring World!! ");
?????????? }
??????????? public void stop() throws Exception {
??? ??????????? System.out.println("Goodbye Spring World!!");
??????????? }
???? }
???? (5) 创建bin目录
???? 编译该类:javac -d bin src/com/manning/sdmia/HelloWorld.java
???? (6) 创建MANIFEST.MF文件
???? 在SRC目录下创建META-INF目录,在该目录下创建MANIFEST.MF文件:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring DM Hello World
Bundle-SymbolicName: com.manning.sdmia.helloworld
Bundle-Version: 1.0.0
Export-Package: com.manning.sdmia
???? (7) hello-world-context.xml文件
???? 在META-INF目录下创建spring目录,在该目录下创建hello-world-context.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"????????????
? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"????????????
? xsi:schemaLocation="http://www.springframework.org/schema/beans?????
? http://www.springframework.org/schema/beans/spring-beans.xsd">
??? <bean id="helloWorld" destroy-method="stop" /> ??????????????????
</beans>
???? (8) 生成JAR文件
???? 先复制META-INF目录至bin目录,执行命令:
???? jar cvfm helloworld.jar src/META-INF/MANIFEST.MF -C bin .
2. 部署
??? install file:helloworld.jar
??? start 14? //14为Bundle Id
3. 网络资源
??? SpringSource OBR:http://ebr.springsource.com/repository/app/
4. Eclipse中开发部署SpringDM Bundle
??? 新建已Target Defination,其中包括上述JAR文件及org.eclipse.osgi-3.5.1.R35x_v20090827.jar,启动。