Grokbase Groups Ant user July 2009
FAQ
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

Search Discussions

  • Stefan Bodewig at Jul 24, 2009 at 8:19 am

    On 2009-07-23, Daniele Development-ML wrote:

    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.
    Thank you for sharing.

    I don't think you need the target at all, you could probably get away
    with creating project and task instances, wire them up and
    invoke execute() on the task instance.

    Something like (untested)

    private static void sign(File file) {
    String sigFile = System.getProperty("user.home") +
    Paths.SIGNATURE_FILE_PATH;

    Project project = new Project();
    SignJar sj = new SignJar();
    sj.setProject(project);
    // probably not needed fo SignJar, but it is part of Ant's lifecycle
    sj.init();

    sj.setKeystore(sigFile);
    sj.setAlias("alias");
    sj.setKeypass("password");
    sj.setStorepass("keyStorePassword");
    sj.setVerbose(true);
    sj.setJar(file);

    sj.execute();
    }

    Stefan

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesant
postedJul 23, '09 at 5:46p
activeJul 24, '09 at 8:19a
posts2
users2
websiteant.apache.org

People

Translate

site design / logo © 2017 Grokbase