- While GRAILS-7274 is not fixed, use try-catch when writing build event handlers;
eventCreateWarEnd = {warName, stagingDir -> try { // Script logic goes here... } catch (Exception e) { e.printStackTrace() throw e } }
- Add log verbosity to Gant, when appropriate:
import org.codehaus.gant.GantState // (...) GantState.verbosity = GantState.VERBOSE ant.logger.setMessageOutputLevel(GantState.verbosity)
- Prefer AntBuilder.path to the use of nested classpath elements:
ant.path(id: 'myClasspath', { pathelement(location: 'somewhere') }) ant.java(classname: 'aClass', dir: 'anyDir', fork: true, classpathref:'myClasspath') {}
The “prize” for having read this far is the necessary snippet to execute the weblogic.appc (among other activities, it will pre-compile the JSPs) after the creation of the .war file of your project:
// _Events.groovy import org.codehaus.gant.GantState eventCreateWarEnd = {warName, stagingDir -> def beaHome = System.getenv('BEA_HOME')?: 'C:/bea' try { println "Executing weblogic.appc ${beaHome} ${warName}" //GantState.dryRun = true GantState.verbosity = GantState.VERBOSE ant.logger.setMessageOutputLevel(GantState.verbosity) File warFile = new File(warName) File tmpFile = new File(warFile.parentFile, "${warFile.name.tokenize('.')[0]}_tmp.war") ant.move(file: warFile, tofile: tmpFile) ant.path(id: 'appcClasspath', { pathelement(location: "${beaHome}/wlserver_10.3/server/lib/weblogic.jar") }) ant.java(classname: 'weblogic.appc', dir: warFile.parentFile, fork: true, classpathref:'appcClasspath') { arg(line: "-output ${warFile.name} -lineNumbers -g -O -keepgenerated ${tmpFile.name}") } } catch (Throwable e) { e.printStackTrace() throw e } }
Additional references:
- Gant scripts, java task and nested classpath element (Grails mailing list)
- Gant scripts, java task and nested classpath element (Groovy mailing list)