How do I make a war project put its classes into a jar and then put that jar into the war instead of the classes themselves directly?


(Paul Jimenez) #1

I’ve got a war project and would like for it to build the classes in that project (under src/main/java) into a .jar and then put that .jar into the war’s WEB-INF/lib/ directory… how do I do this?

BTW, I’ve been much impressed by the ease and flexibility of the war { from “…” { include … into … } } specs. Much nicer than copying everything around.


(richard murray) #2

I managed to do this with the following

jar.enabled = true
  war {
    baseName = 'crm_web'
    dependsOn jar
    from "web/contents"
    classpath = jar.archivePath
    webInf { from 'web/webinf' } // adds a file-set to the WEB-INF dir.
    webXml = file('web/web.xml') // copies a file to WEB-INF/web.xml
       }

(Luke Daley) #3

FYI - as of milestone 6 you should be able to do the following:

jar.enabled = true
war {
    baseName = 'crm_web'
    from "web/contents"
    classpath = jar
    webInf { from 'web/webinf' } // adds a file-set to the WEB-INF dir.
    webXml = file('web/web.xml') // copies a file to WEB-INF/web.xml
       }

Gradle will work out task dependencies here.