Java Reference
In-Depth Information
L ISTING 9.4
The Native Windows Executable
echo Installing..
echo Installed.
When preparing this example, remember that the JAR must contain both the Java class (in the
right path) and the install.bat executable too. The JAR file has to be signed; otherwise, the
JNLP Client will deny its execution. After all, we are requesting to save a file on the client
filesystem a file and then execute it. Your customers should really trust you to allow this on
their computers!
Now let's see Listing 9.5, which supplies the InstallWin Java class.
L ISTING 9.5
The InstallWin class
package com.marinilli.b2.c9;
import javax.jnlp.*;
import java.io.*;
import java.net.URL;
/**
* Chapter 10 - Installs native code and executes it
* @author Mauro Marinilli
* @version 1.0
*/
public class InstallWin {
static ClassLoader loader;
static boolean deleteTempFile = true;
static final String tempFileName = “temp.bat”;
public static void main(String[] args) {
if (args.length>0) {//checks whether to remove the temp file
if (args[0].equalsIgnoreCase(“leaveTempFile”))
deleteTempFile = false;
9
}
loader = Thread.currentThread().getContextClassLoader();
extractNativeResource(“install.bat”);
executeNativeResource(tempFileName);
if (deleteTempFile) {
deleteTempFile(tempFileName);
}
System.out.println(“installation terminated.”);
System.exit(0);
}
Search WWH ::




Custom Search