Osgi web application bundles

Is there any way to create an osgi web app. bundle (wab) with gradle?

I tried to start a simple project with the osgi plugin. I managed to get the right manifest enties in the jar and to place files and folders from src/main/webapp into it, but I can’t put the move the classes into /WEB-INF/classes from the root of the jar.

I also tried to use the war plugin besides the osgi (and scala) plugin(s) to get the right content of the archive but I could not place the manifest entries into the war, rename it to jar and remove the WEB-INF/lib folder from it.

I don’t know which is the right approach of the problem.

I’m very desperate to find a way after three days of googling and trying.

Hi Péter, I think the best way to start is to use the the OSGi plugin and generate the wab manually by using a creating a custom Jar task.

regards, René

I’ve created a snippet for the wab task you can use as a starting point:

apply plugin: 'java'
apply plugin: 'osgi'
  ...
...
  task wab(type:Jar){
 manifest = osgiManifest {
            instruction 'Web-ContextPath', '/foo'
             classesDir = project.sourceSets.main.output.classesDir
            classpath = project.configurations.runtime
        }
        baseName = "FooWAB"
          from 'src/main/webapp'
            into("WEB-INF/classes"){
       from sourceSets.main.output
        }
}

regards, René

Hi René,

Thank you very much. In your snippet what is the ‘baseName’ setting for?

Before I’ve read your reply I had come up with a similar solution:

apply plugin: 'java'
apply plugin: 'osgi'
...
  jar {
 manifest {
  // some instructions...
  ...
  instruction 'Web-ContextPath', '/foo'
  instruction 'Bundle-ClassPath', 'WEB-INF/classes'
 }
 into 'WEB-INF/classes'
 from('src/main/webapp') {
  into '/'
 }
}

Regards, Péter

Hi Péter, I’ve just used the baseName property to set another name to the archive of that task. Details about the archive naming conventions you can find at the DSL reference for the Jar task: http://gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:archiveName

regards, René

I’m trying to figure out how to use Gradle to build a web app bundle (WAB). So far, I’ve been using the osgi plugin to create standard bundles ok.

In the time since this discussion, has anything changed in terms of how this is best implemented?