Hello everybody,
some time ago I emailed to ask details/examples on how
to programmatically invoke Ant libraries to sign a jar file. There were
contrasted opinion on whether Ant libraries could be invoked directly and I
was invited to post an example when (and if) I was successful in this.
With a considerable delay (apologies for this):
Please find below the code - hopefully it will be useful to somebody else.
private static void sign(File file) {
String sigFile = System.getProperty("user.home") +
Paths.SIGNATURE_FILE_PATH;
Project project = new Project();
Target target = new Target();
SignJar sj = new SignJar();
target.addTask(sj);
project.addTarget("sign_jar", target);
sj.setKeystore(sigFile);
sj.setAlias("alias");
sj.setKeypass("password");
sj.setStorepass("keyStorePassword");
sj.setProject(project);
sj.setVerbose(true);
sj.setJar(file);
project.executeTarget("sign_jar");
}
Daniele