1. Use jar to package the legacy binary into platform dependent jar files. Use jarsigner to sign the binary package jar file
Before using jarsigner, you may need create some keystore with keytool. Some examples are:
keytool -genkey -keystore abc.ks -alias abc -validity 365
keytool -genkey -keystore securityKM.ks -alias master -validity 365
keytool -selfcert -keystore securityKM.ks -alias master -validity 365
keytool -export -file securityKM.cert -keystore securityKM.ks -alias master -v
keytool -printcert -file securityKM.cert
keytool -import -file securityKM.cert -alias master -keystore abc.ks
keytool -list -keystore abc.ks
2. Prepare the JNLP file with platform dependent resource properties. An example as:
3. Client click the JNLP and download the jar file. Using the code below to load and unpack binary
String os = System.getProperty("os.name");
ClassLoader classLoader = getClass().getClassLoader();
URL url;
int n;
byte[] b = new byte[8092];
InputStream is;
FileOutputStream fs;
if(os.startsWith("Windows")){
url = classLoader.getResource("mybinary.exe");
is = url.openStream();
fs = new FileOutputStream("mybinary.exe");
n = 0;
while ((n = is.read(b)) >0) fs.write(b, 0, n);
is.close();
fs.close();
else if(os.equals("Linux")){
...
4. After the binary jar file is unpacked. Start the binary with
if(os.startsWith("Windows")){
Processro1 pro = Runtime.getRuntime().exec("mybinary.exe " + args);
}else if(os.equals("Linux")){
....
Comments
Post a Comment