Deploying OSGi services
You build your OSGi service and deploy it to Insight Server. You can then review the state of the deployment in the server logs and in the OSGi console.
Before you begin
About this task
Procedure
- Create a build.xml file at the root
of your OSGi feature project. Use the following example
as a template for your build file:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE layout> <!-- Licensed Materials - Property of IBM --> <!-- 5725-B69 5655-Y17 5724-Y00 5724-Y17 5655-V84 --> <!-- US Government Users Restricted Rights - Use, duplication or --> <!-- disclosure restricted by GSA ADP Schedule Contract with --> <!-- IBM Corp. --> <project name="Passenger Service" default="build" basedir="."> <property name="is.home" value="<InstallDir>" /> <!-- If you change the version number, don't forget to also do it in the --> <!-- target "deploy.feature.extension" that modifies the server.xml file. --> <property name="jar.version" value="1.0.0" /> <property name="service.project" value="${basedir}/../service.service_name" /> <property name="server.name" value="server_name" /> <property name="server.path" value="${wlp.user.dir}/servers/${server.name}" /> <!-- If you change the "service.name" property, don't forget to also do it in the --> <!-- target "deploy.feature.extension" that modifies the server.xml file. --> <property name="service.name" value="service.service_name_${jar.version}" /> <property name="jar.file" value="${service.name}.jar" /> <property name="esa.file" location="${service.name}.esa" /> <target name="check.system"> <condition property="windowsFamily"> <os family="windows" /> </condition> <condition property="unixFamily"> <os family="unix" /> </condition> </target> <target name="clean" description="Clean the built files"> <delete failonerror="false" > <fileset dir="${service.project}/bin" includes="**/*.*"/> </delete> <delete failonerror="false"> <fileset dir="." includes="*.esa"/> </delete> <delete failonerror="false"> <fileset dir="." includes="*.jar"/> </delete> </target> <path id="build.classpath"> <fileset dir="${is.home}/runtime/wlp/lib/"> <include name="org.eclipse.osgi*.jar" /> </fileset> </path> <target name="build" depends="clean" > <!-- BUILD JAR --> <mkdir dir="${service.project}/bin" /> <javac destdir="${service.project}/bin" fork="true" classpathref="build.classpath"> <src path="${service.project}/src" /> </javac> <zip destfile="${jar.file}"> <fileset dir="${service.project}/bin" includes="**/*.*" /> <fileset dir="${service.project}/BundleContent" includes="**/*.*" /> </zip> <!-- BUILD ESA --> <zip destfile="${esa.file}"> <fileset dir="${basedir}" includes="**/*.jar" /> <fileset dir="${basedir}" includes="OSGI-INF/*.*" /> </zip> </target> <target name="install.feature.Windows" if="windowsFamily"> <exec executable="${is.home}/runtime/wlp/bin/featureManager.bat" dir="${basedir}"> <arg value="install" /> <arg value="--when-file-exists=replace" /> <arg value="${esa.file}" /> </exec> </target> <target name="install.feature.Unix" if="unixFamily"> <exec executable="${is.home}/runtime/wlp/bin/featureManager" dir="${basedir}" > <arg value="install" /> <arg value="--when-file-exists=replace" /> <arg value="${esa.file}" /> </exec> </target> <target name="install.feature.extension" depends="check.system"> <antcall target="install.feature.Windows" inheritAll="true" /> <antcall target="install.feature.Unix" inheritAll="true" /> </target> <target name="test.server.configured"> <!-- test ${server.path}/server.xml file contains (as a comment) START: osgi sample --> <condition property="server.configured"> <resourcecontains resource="${server.path}/server.xml" substring="usr:${extension.full.name}"/> </condition> </target> <target name="deploy.feature.extension" depends="test.server.configured" unless="server.configured"> <!-- Add following info to server.xml in server - featureManager --> <replace file="${server.path}/server.xml"> <replacetoken><![CDATA[</server>]]></replacetoken> <replacevalue><![CDATA[ <!-- START: osgi sample --> <featureManager> <feature>usr:service.service_nameFeature_1.0.0</feature> </featureManager> <!-- END: osgi sample --> </server>]]></replacevalue> </replace> </target> <target name="install" > <antcall target="install.feature.extension" inheritAll="true" /> <antcall target="deploy.feature.extension" inheritAll="true" /> </target> </project> - Edit the is.home property to match your installation directory.
- If your Insight Server is not running, start it.
- Open a command prompt at the level of the build.xml file, and enter the ant command. You might need to configure the JAVA_HOME environment variable to point to your Java Development Kit, and the ANT_HOME environment variable to point to the <InstallDir>/shared/tools/ant folder. This command builds the .jar and .esa archives from your feature.
- Enter the ant install command to deploy the .esa file to the server. A new entry for the feature is added to the server.xml file.
- Optional: Verify the deployment of the service
by reviewing the log.
- Open the console.log file in <WLP_USER_DIR>/servers/cisDev/logs in a text editor.
- Scroll to the bottom of the log and look for the message that says that the server installed your feature: CWWKF0012I: The server installed the following features: [usr:service.service_nameFeature_1.0.0] The ready message indicates that the service is deployed and active.
- Close the console.log file.
- Optional: Verify the deployment of the service
by using the OSGi console.
- In the command window, type the following command: telnet localhost 5471.
- Search for a service and verify that it is tagged as ACTIVE, preceded by an identifying number. For example, type lb Age to search for a service that contains Age in its name.
- Type bundle <identifier>, where <identifier> corresponds to the identifying number from the previous step. The console displays the exported package of the service and additional information.
Results
Parent topic: Implementing OSGi services