I'd like to bundle some jar files built with Gradle 1.6 as part of a Java webstart application.
I can currently sign the jars correctly with a certificate and specify the codebase
and permissions
attributes for the produced artifacts by using the standard jar task like so:
jar {
manifest.attributes provider: 'tribe7.net'
manifest.attributes permissions: 'all-permissions'
manifest.attributes codebase: '*'
}
This is because the latest Java webstart version in Oracle's JDK/JRE makes these attributes mandatory or else it complains to the user about the application's security.
Preventing RIAs from Being Repurposed
However, my artifact jars have third party dependencies (for example, slf4j) and I have yet to find an intuitive way to include these atributes in such third party jars. With this in mind, my final webstart application structure looks sort of like this:
./build/webstart/my.jnlp
./build/webstart/lib/myartifactA-1.00.jar
./build/webstart/lib/myartifactB-1.00.jar
./build/webstart/lib/myartifactC-1.00.jar
./build/webstart/lib/slf4j-api-1.7.5.jar
The result is that at runtime, webstart doesn't complain about my artifacts but does so for the third party jars because they obviously don't have the attributes in their manifest file:
Missing Codebase manifest attribute for: file:/C:/build/webstart/lib/slf4j-api-1.7.5.jar
Missing Permissions manifest attribute for: file:/C:/build/webstart/lib/slf4j-api-1.7.5.jar
Missing Codebase manifest attribute for: file:/C:/build/webstart/lib/slf4j-simple-1.7.5.jar
Missing Permissions manifest attribute for: file:/C:/build/webstart/lib/slf4j-simple-1.7.5.jar
Since I don't directly control the manifest generation for the third party jars I have to somehow modify the manifest files present inside the build/webstart/lib
directory to explicitly include those attributes in order to make webstart happy.
Is there a way to add attributes to a jar file's manifest with Gradle? In case anyone's interested, this is my Gradle build script:
Thanks for your time and help!
UPDATE
Peter's answer worked! This is the updated code:
ant.jar(destfile: it, update: true) {
delegate.manifest {
attribute(name: 'permissions', value: 'all-permissions')
attribute(name: 'codebase', value: '*')
}
}
ant.signjar(
destDir: webstartSignedLibPath,
alias: project.getProperty('jarsign.keystore.alias'),
jar: it,
keystore: project.getProperty('jarsign.keystore.path'),
storepass: project.getProperty('jarsign.keystore.password'),
preservelastmodified: 'true'
)
Thanks!