Building a J2EE Connector Architecture(JCA) RAR file and packaging in ear


(suriya_sena) #1

I have the requirement to add a JCA resource adapter to an ear file.

Since there isn’t a build it plugin for a resource, I have tried using the war plugin and then renaming the war to rar file. The ear plugin however expects a war file created for a web project. How do I get the ear plugin to add the rar file to the ear?


(suriya_sena) #2

I was able to build the JCA Resource adapter using the following script. The application ear build script declares a dependency on the resource adapter archive. e.g

build script for resource adapter.

apply plugin: 'java'
  dependencies {
   compile project(':Project1)
   compile files('../../ProjectLibrary/lib/j2ee/1.4/j2ee-1.4.jar');
}
  sourceSets {
   main {
      java {
         srcDir
"$project.name/connectorModule"
       }
   }
}
  //
variable for the name of the resource adapter jar that will be included in rar file.
project.ext.set("connectorFile","ra.jar")
  //
This task creates the connector jar i.e. classes for the resource adapter.
//
The connector jar will be included in the rar file
  task rarjar(type: Jar) {
   archiveName connectorFile
     from ('build/classes/main') {
      include '**/*'
   }
}
    jar {
     // Change the archive extension so that the application ear project includes
    //
resource adapter as a .rar file instead of .jar
          extension="rar"
     // The connector classes are packaged into the ra.jar file, they can be excluded from the rar file.
   // also suppress empty directories from being included.
          includeEmptyDirs=false
   exclude("**/*.class")
          into('/META-INF'){
     from "$project.name/connectorModule/META-INF/ra.xml"
   }
     into('/'){
     from "build/libs"
     include connectorFile
   }
}
  jar.dependsOn rarjar