Gradle Deployment Project for Ears

I have a 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 a PRJ.ear file with the structure below:

 --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 

Unable to create APP-INF/classes

+7
java web-applications gradle weblogic ear
source share
2 answers

I'll start by observing: both ear instances in your build script are for the same task. There is no need to refer to ear twice, i.e. into ads can go up one level.

First add the APP-INF/src folder as the source. This will add the compiled classes to the root of the EAR, so you should exclude them. Then you should tell ear task to copy the compiled classes to the APP-INF/classes 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 } 
+2
source share

To include the .ear , you must modify build.gradle by adding the apply plugin: 'ear' and filling out the ear block correctly by following the instructions in this guide .

In addition, the magic of the deployment process is pretty well explained here soon about using the wideploy tool in Gradle. You can also look here to find more information about this script.

+5
source share

All Articles