Modify Context Root

I’m building an ear with an external dependency on a war. The build works and I can deploy the ear to my WebSphere server and have it work, but the war is at the wrong context. How do I modify the generated web-module’s context-root?

What I have:

...
ear {
  baseName = 'myProjectEAR'

  deploymentDescriptor {
    webModule("myProject.war","/")
  }
}

dependencies {
  deploy group: "com.myCompany", name: "myProject", version: "0.1.3-SNAPSHOT", changing: true
}

...

This results in the following application.xml:

<?xml version="1.0"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
  <module>
    <web>
      <web-uri>myProject.war</web-uri>
      <context-root>/</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>myProject-0.1.3-20151216.214129-5.war</web-uri>
      <context-root>myProject-0.1.3-20151216.214129-5</context-root>
    </web>
  </module>
  <library-directory>lib</library-directory>
</application>

Not the desired outcome. How do I change the context-root on the second module? I’m sure it’s something simple like correctly specifying the dependency or artifact in ear.deploymentDescriptor.webModule, but I cannot figure out how to do that.

 ear {
      baseName = 'multi-module-project'

     deploymentDescriptor {
         webModule("admin-" + project(":admin").getVersion() + ".war", "/admin")
    }
 }

This works for the module where version name applied. cheers !!

1 Like