Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle deploy project to ear

I have project with below structure

--MyPrj.ear
  --APP-INF
    --src
    --lib
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml

I want to deploy to PRJ.ear file with below structure:

--MyPrj.ear
  --APP-INF
    --classes
    --lib
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml

And here is my ear configuration:

ear {
    baseName 'PRJ'
    appDirName 'APP-INF/src'
    libDirName 'APP-INF/lib'

    ear{
        into("META-INF"){
            from("META-INF") {
                exclude 'application.xml'
            }
        }
        into("WEB_MAIN") {
            from ("WEB_MAIN")
        }
    }

    deploymentDescriptor {
        webModule 'WEB_MAIN', '/'
        applicationName = "PRJ"
    }
}

My actual result:

--MyPrj.ear
  --APP-INF
    --lib
  --com
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml

Cannot generate APP-INF/classes

like image 608
Luc Avatar asked Aug 12 '15 09:08

Luc


2 Answers

To include .ear file you should modify build.gradle by adding apply plugin: 'ear' to it and filling the ear block correctly by following the instructions in this guide.

Also, the magic of deployment process is quite well explained here, shortly it's about using wideploy tool in Gradle. You may also want to take a look here to find some more detailed info about this script.

like image 75
solar Avatar answered Nov 19 '22 15:11

solar


I'll start with an observation: Both instances of ear in your build script refer to the same task. There is no need to refer to ear twice, i.e. the into declarations can go one level up.

First, add the folder APP-INF/src as a source set. This will result in the compiled classes being added to the root of the EAR, so you have to exclude these. Then you have to tell the ear task to copy the compiled classes to the APP-INF/classes directory in the EAR:

// Make sure the source files are compiled.
sourceSets {
    main {
        java {
            srcDir 'APP-INF/src'
        }
    }
}

ear {
    baseName 'PRJ'
    libDirName 'APP-INF/lib'

    into("META-INF") {
        from("META-INF") {
            exclude 'application.xml'
        }
    }
    into("WEB_MAIN") {
        from("WEB_MAIN")
    }

    deploymentDescriptor {
        webModule 'WEB_MAIN', '/'
        applicationName = "PRJ"
    }

    // Exclude the compiled classes from the root of the EAR.
    // Replace "com/javathinker/so/" with your package name.
    eachFile { copyDetails ->
        if (copyDetails.path.startsWith('com/javathinker/so/')) {
            copyDetails.exclude()
        }
    }

    // Copy the compiled classes to the desired directory.
    into('APP-INF/classes') {
        from(compileJava.outputs)
    }

    // Remove empty directories to keep the EAR clean.
    includeEmptyDirs false
}
like image 3
Johan Stuyts Avatar answered Nov 19 '22 16:11

Johan Stuyts