使用maven,Apache ServiceMix开发OSGI web例子

一:创建maven的webapp项目 ppweb

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>com.lala</groupId>
	<artifactId>ppweb</artifactId>
	<packaging>war</packaging>
	<version>1.0.0</version>

	<name>ppweb Maven Webapp</name>
	<url>http://maven.apache.org</url>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>

	<build>
		<finalName>ppweb</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			<plugin>  
                <groupId>org.apache.tomcat.maven</groupId>  
                <artifactId>tomcat7-maven-plugin</artifactId>  
                <version>2.2</version>  
                <configuration>  
                    <path>/</path>  
                    <port>9090</port>  
                    <uriEncoding>UTF-8</uriEncoding>  
                </configuration>  
            </plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>false</addClasspath>
							<classpathPrefix>WEB-INF/lib/</classpathPrefix>
						</manifest>
						<manifestEntries>
							<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
							<Class-Path>${project.build.finalName}.jar</Class-Path>
							<Bundle-Name>${project.groupId}.${project.ArtifactId}</Bundle-Name>
							<Bundle-SymbolicName>${project.groupId}.${project.ArtifactId}</Bundle-SymbolicName>
							<Bundle-Version>${project.version}</Bundle-Version>
							<Bundle-Vendor>${project.groupId}</Bundle-Vendor>
							<Import-Package>
								org.osgi.framework,
								javax.servlet.http,
								javax.servlet
							</Import-Package>
							<Embed-Dependency>*</Embed-Dependency>
							<DynamicImport-Package>*</DynamicImport-Package>
							<Web-ContextPath>/ppweb</Web-ContextPath>
							<Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

注意:这里的tomcat7-maven-plugin插件,可有可无,这里是为了方便在本地运行(mvn tomcat7:run)


二:

编辑src/main/java/webapp/index.jsp文件,随便增加一些内容


三:

下载apache-servicemix,并且解压


四:

打包上面的web项目,mvn package

把生成的war扔到apache-servicemix的deploy目录下


最后,启动apache-servicemix,执行bin/servicemix.bat

在弹出的窗口中,输入list,可以看到bundle 列表


看到,这里的ppweb项目已经安装成功了


打开浏览器,输入http://127.0.0.1:8181/ppweb,即可访问

注意,web端口默认为8181

这里的/ppweb,是上面Web-ContextPath的配置,需要保持一致

你可能感兴趣的:(maven,osgi)