JarSigner done within java?
Is it possible to use the JarSigner class to sign a jar file within java? Currently I am using:
String args[] = {"-keystore", keystore, "-storepass", password, jar, keyname};
JarSigner js = new JarSigner();
js.run(args);
but if 开发者_高级运维anything fails, the js.run void will call a System.exit(-1) causing my entire application to crash. I was thinking about running that inside of a thread, joining it until it completes, and checking for the return code. Just seeing if there is a more formal way of doing that... Any help would be appreciated.
I suppose you use Sun/Oracle JarSigner
included in JDK tools. You have two option:
Reuse by copy/paste most of the
run
method to skip theSystem.exit
incatch
clause from the OpenJDK source for instanceUse JarSigner from GNU ClassPath project which
start
method does not invokeSystem.exit
but throws exceptions.
If you sign only with SHA1withRSA algorithm, there is a project called zip-signer. The main target of this project is Android, but the core library of this project, "zipsigner-lib", doesn't depend on Android system so it works in PC as well. You can take a look at sample code for PC named zipsigner-cmdline.
If you need algorithms other than SHA1withRSA, though, you'll probably have to adapt source codes from the GNU ClassPath project, which is no easy task.
精彩评论