Search code examples
mavenosgiwarapache-servicemix

Deploying simple war as OSGi bundle in ServiceMix


I have written an incredibly simple (no java files) war file which I am hoping to deploy to servicemix. It has the following directory structure:

.
|-src
  |-main
    |-webapp
      |-css
      |-js
      |-WEB-INF
        \-web.xml
      \-index.html
\-pom.xml

I am able to deploy this to the jetty container running in ServiceMix using the following commands:

>install war:file:///<Fully qualified war location>?Webapp-Context=<Application name>
>osgi:start <Bundle id>
>http://localhost:8181/<Application name>/index.html

What I would prefer is to hot-deploy as I do with the rest of my bundles. What should the pom.xml look like? The simpler the better.


Solution

  • This has done the trick for me (although I did need to add a placeholder java file to ensure target/classes was generated):

    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
        <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>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>jar</supportedProjectType>
                    <supportedProjectType>bundle</supportedProjectType>
                    <supportedProjectType>war</supportedProjectType>
                </supportedProjectTypes>
                <instructions>
                    <Bundle-Version>${pom.version}</Bundle-Version>
                    <Webapp-Context>webclient</Webapp-Context>
                    <_include>-osgi.bnd</_include>
                </instructions>
            </configuration>
        </plugin>
    </plugins>