Note: Read the Code example disclaimer for important legal information.
////////////////////////////////////////////////////////////////////////////////// // // Install/Update example. This program uses the AS400ToolboxInstaller class // to install and update the IBM Toolbox for Java package on the workstation. // // The program checks the target path for the IBM Toolbox for Java package. // If the package is not found, it installs the package on the workstation. // If the package is found it checks the source path for updates. If // updates are found they are copied to the workstation. // // Command syntax: // checkToolbox source target // // Where // source = location of the source files. This name is in URL format. // target = location of the target files. // ////////////////////////////////////////////////////////////////////////////////// import java.io.*; import java.util.*; import java.net.*; import utilities.*; public class checkToolbox extends Object { public static void main(String[] parameters) { System.out.println( " " ); // Continue with the install/update only if both source and target // names were specified. if (parameters.length >= 2) { // The first parameter is the source for the files, the second is the target. String sourcePath = parameters[0]; String targetPath = parameters[1]; boolean installIt = false; boolean updateIt = false; // Created a reader to get input from the user. BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in),1); try { // Point at the source package. AS400ToolboxInstaller uses the URL // class to access the files. URL sourceURL = new URL(sourcePath); // See if the package is installed on the client. If not, ask the user // if install should be performed at this time. if (AS400ToolboxInstaller.isInstalled("ACCESS", targetPath) == false) { System.out.print("IBM Toolbox for Java is not installed. Install now (Y/N):"); String userInput = inputStream.readLine(); if ((userInput.charAt(0) == 'y') || (userInput.charAt(0) == 'Y')) installIt = true; } // The package is installed. See if updates need to be copied from the // server. If the target is out of data ask the user if update should // be performed at this time. else { if (AS400ToolboxInstaller.isUpdateNeeded("ACCESS", targetPath, sourceURL) == true) { System.out.print("IBM Toolbox for Java is out of date. Install fixes (Y/N):"); String userInput = inputStream.readLine(); if ((userInput.charAt(0) == 'y') || (userInput.charAt(0) == 'Y')) updateIt = true; } else System.out.println("Target directory is current, no update needed."); } // If the package needs to be installed or updated. if (updateIt || installIt) { // Copy the files from the server to the target. AS400ToolboxInstaller.install("ACCESS", targetPath, sourceURL); // Report that the install/update was successful. System.out.println(" "); if (installIt) System.out.println("Install successful!"); else System.out.println("Update Successful!"); // Tell the user what must be added to the CLASSPATH environment // variable. Vector classpathAdditions = AS400ToolboxInstaller.getClasspathAdditions(); if (classpathAdditions.size() > 0) { System.out.println(""); System.out.println("Add the following to the CLASSPATH environment variable:"); for (int i = 0; i < classpathAdditions.size(); i++) { System.out.print(" "); System.out.println((String)classpathAdditions.elementAt(i)); } } // Tell the user what can be revmoed from the CLASSPATH environment // variable. Vector classpathRemovals = AS400ToolboxInstaller.getClasspathRemovals(); if (classpathRemovals.size() > 0) { System.out.println(""); System.out.println("Remove the following from the CLASSPATH environment variable:"); for (int i = 0; i < classpathRemovals.size(); i++) { System.out.print(" "); System.out.println((String)classpathRemovals.elementAt(i)); } } } } catch (Exception e) { // If any of the above operations failed say the operation failed // and output the exception. System.out.println("Install/Update failed"); System.out.println(e); } } // Display help text when parameters are incorrect. else { System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("Parameters are not correct. Command syntax is:"); System.out.println(""); System.out.println(" checkToolbox sourcePath targetPath"); System.out.println(""); System.out.println("Where"); System.out.println(""); System.out.println(" sourcePath = source for IBM Toolbox for Java files"); System.out.println(" targetPath = target for IBM Toolbox for Java files"); System.out.println(""); System.out.println("For example:"); System.out.println(""); System.out.println(" checkToolbox http://mySystem/QIBM/ProdData/HTTP/Public/jt400/ d:\\jt400"); System.out.println(""); System.out.println(""); } System.exit(0); } }