Moving jars to root of war causing problems


(Mike Nakhimovich) #1

I’m converting an old project to gradle from ant, the project uses java applets and as a result wants certain jars to be at the root of the war instead of inside web-inf/lib. The following code appears to do what I need it to if I put it inside of the war task

from(configurations.runtime) {

into “lib”

}

The end result of the above code is that I have a lib folder at the root of the war containing all my jars (correct), unforunately if I try to open any of the jar files, for instance running jar -tvf jarName.jar I get an error “java.util.zip.ZipException: error in opening zip file”. I’ve also tried moving the files using:

into(‘lib’) {

from ‘lib’ //location of my lib folder pertaining to my projectDir

}

interestingly enough if I add the following tasks, I get an exploded war with everything that I need, the lib folder is at the root and the jars are normal. It seems specifically that a move of jars from within a war task gives me jars that I cannot expand

task explodedWar(type: Copy) {

into “$buildDir/exploded”

with war

}

task moveLib(type: Copy) {

into “$buildDir/exploded/lib”

from “$buildDir/exploded/WEB-INF/lib”

}

war.dependsOn moveLib

moveLib.dependsOn explodedWar

Is there a different way that I can have a folder at the root of my war that contains all the jars from lib directory which is local to my project?

More detail:

this is my projectdir

project.iml

gradle

build

gradle.properties

build.gradle

gradlew

src

build.properties

gradlew.bat

build.xml

libraries

dependencies {

compile fileTree(dir: ‘libraries’, include: ‘*/.jar’)

war {

from(configurations.runtime) {

into “lib”

}

//also tried the below

// into “lib”

// from “libraries”

}

Gradle version: 1.9

Mac

Why would moving jars during the war task result in jar files that are corrupted, while moving jar files during a custom explodedWar task make everyone behave as expected?