![]() ![]() ![]() |
||||||||||||||
![]()
Introduction Deploying a Java program consists of collecting the
various Java class files and perhaps web pages together and copying them to a location on
a server or client computer where users can access them.
Quicksteps for deploying beans, applications, and appletsBelow are the general steps required to successfully deploy your program: Bean deployment quickstepsBeans are usually deployed either alone, or with other beans in a Java archive (.jar) file. For more information on JavaBean development and deployment, see Beans Express. Application deployment quickstepsAdd all the files you use to your project using the Add to
Project button Deployment issuesThe following questions need to be answered so you can determine the best deployment strategy: Is this an applet or an application? From strictly a deployment standpoint, the main difference between the two is that for
an application your user will need to use Does your program rely on JDK 1.1 features?If you are developing an applet, this might be an issue as some users may be using Internet browsers which have not been updated to support applications written with JDK 1.1 features. JDK 1.0.2 compliant browsers do not support JAR archives, therefore if you have written a JDK 1.0.2 compliant applet and wish to deploy it, be sure to select the ZIP archive format when using the Deployment Wizard, or put the classes unarchived on the server. It is more efficient to use an archive as the user will contact the server once for the zip file, rather than dozens of times, downloading each and every class. For more information on deploying applets for JDK 1.0.2 browsers, see How to build and deploy a 1.0.2 applet for a 1.0.2 browser below. Is the target user an Intranet user, an Internet user, or both? Answering this question can help you decide whether to develop an application or an applet. The main advantage of an applet is that it can be easily updated and maintained. The main advantage of the application is that it has fewer runtime limitations. If you are deploying to the Internet, building an applet might be the wiser choice. However, you need to be very sure that everything the applet needs is downloadable from the server it is on, or is on the client machine already. Also, no matter which browser your applet runs in, the applet needs to have enough information inside the APPLET tag to allow the applet loader to find all the classes, images and other files your applet needs. Does the user already have Java libraries installed locally? If your program uses components which rely on the JBCL and JGL archives, you need to
ensure that your users have the redistributable classes (such as jbcl-rt.zip, or jbclstd-rt.zip,
and jgl.zip) on their CLASSPATH, or you need to deploy the needed JBCL and JGL
classes with your program. The actual names of the redistributable files may be different,
depending on which version of JBuilder you have. To see what redistributable files you
need to include, look in the If you can assume that all the users already have these archives in their environment, either because the users already have them installed, or you have provided it to them using some kind of installation process, then you can deliver applications and applets which do not have to contain these packages. If you can not assume that your user has these libraries, you will need to provide them. This is particularly true in the case of an applet deployment. When you deploy your applet, you will need to deploy these libraries and any other needed resources to the server. If you use the Deployment Wizard to create your archive, just check Include JBCL and Include JGL to add these files to the archive file. The Deployment Wizard can assist you in archiving you files for deployment because it can identify all the package and class dependencies. To get the Deployment Wizard to deploy the necessary classes in your archive, check the "include JBCL", "include JGL", and "include all others" checkboxes, and the necessary class files will be added to the archive. See Also: One of the first questions you have to answer is whether or not to place your program into an archive. The biggest factors in this decision will be download time and program size. One of the advantages of using the Deployment Wizard to create an archive is that only necessary files are included. The Deployment Wizard identifies all of the classes the project needs to use and bundles them into one archive. This allows for efficient download time, disk usage, and network socket consumption when the application or applet is launched from a browser. Any applet that has more than one class file benefits from an archive. Preparing a Java program for deploymentThe following rules apply to deploying beans, applications, or applets: Deploying Java applicationsDeployment of a stand-alone Java application consists of placing its .class or archived .class files onto the machine where it will run, or onto a server accessible from the runtime machine, and then running it using a copy of the Java virtual machine (VIM). If you want to minimize the load on your web server, using archives minimizes the number of web "hits" necessary for the VM to load all its classes. The VM will download the archive in one connection, and execute it from there. If an archive is not used, and 200 class files are stored on the web server, for example, 200 individual "hits" are going to occur as the VM attempts to load each class. When developing the application, you can use the program Instead, when deploying your applications, use There is a difference in how For more information, see the JRE download web site at: http://java.sun.com/products/jdk/1.1/index.html.
In summary, use
Deploying appletsSetting up your working environmentThe key to combining development and deployment is managing what files go where. As a rule, it's a good idea to keep your source code deliverables in a different hierarchy than your development tools. This keeps the irreplaceable items out of harms way. By default, JBuilder tries to keep all source files in one place and all deliverables (class files) in a different place. In general, this is a good thing with the small exception of the HTML file that launches an applet. JBuilder likes to think of this as part of the "source", but for applets it is really a deliverable because the applet is useless without it. You'll find the deployment process easier if you make your project working environment reflect the reality of a deployed applet, bringing your development a little closer to instant deployment. This means that your HTML file needs to be moved (a simple rename will do it) to the directory above your class hierarchy (where your compiled files go). Once you have your applet built and running in this situation you can run the Deployment Wizard to grab everything and stick it in one JAR file. After that is done, you can exit JBuilder and test your applet with any and all the browsers you need to use. Example applet projectThe following example shows you how to set up an applet project that minimizes deployment difficulties. To follow the example steps below, create a The project's finished directory structure will look like this:
Close all existing projects and create a new project and applet using the wizards on the File menu. Distributables In your JBuilder installation directory, there are two files, LICENSE.TXT, and DEPLOY.TXT. The DEPLOY.TXT file describes what files you may distribute, and LICENSE.TXT describes Borland's No-Nonsense license, and describes in legal-ese what you may distribute. Quoting the LICENSE.TXT file directly:
JBuilder Distributable Components Java Beans Component Library (JBCL) - The JBCL consists of jbcl-rt.zip in the \jbuilder\redist directory, and/or the individual files in that archive. ObjectSpace Java Generic Libary (JGL) - The JGL class files under the terms of your licensing; the redistributables for JGL are defined as the jgl.zip file in the \jbuilder\redist directory. KLGroup JClass - The class files under the terms of your licensing, the redistributables for JClass are defined as the jclass.zip file in the \jbuilder\redist directory. Instead of trying to distribute all of the class libraries accompanying JBuilder, its best that you use the Deployment Wizard included with JBuilder to create the .ZIP or .JAR file(s) for use in deploying your target Application, Applet, or Java Bean component. This will assure that you have everything needed to deploy your Java code. Sun's Java Runtime Distributables Sun's suggestion for distribution of the Java Runtime (JRE) varies from platform to platform. For Win32, it is suggested that the developer direct users to download the JRE directly from Sun, as it comes with an installer suitable for end-users. An installer is not available for the Solaris version, so the developer should bundle the Solaris JRE and an installer with their Solaris applications. The just-in-time compilerAppAccelerator is a just-in-time (JIT) compiler. This add-on compiles Java Virtual Machine codebytes into native operating system codebytes on the fly. AppAccelerator is an operating system add-on for the end-user's computer, to make .class files run faster. AppAccelerator does not produce additional .class files, but rather, processes .class files on the fly. When you issue a compile command, such as Make or Rebuild, the regular compiler produces cross-platform classes that are used for all platforms. Then, with the JIT compiler running on any of the platforms, the class files run faster on that platform. The JIT compiler is currently provided for Windows 95 and Windows NT; other platforms will be supported. JBuilder uses the JIT by default for the IDE itself and for the target application when run from the IDE. To run the JIT when using command line tools, the user's command-line environment variables must be set. Note: The AppAccelerator is not deployable. See Setting environment variables for command-line tools in the JBuilder User's Guide Other Distributables If you are programming with any third party class libraries that do not accompany JBuilder, such as a JDBC driver, it should also be distribtued with your code as well. One such example is Borland's InterClient, which allows your Java applications to communicate with Borland's InterBase. The interclient.jar file is used with JBuilder to compile applications, and should accompany any InterBase enabled applications you develop. The interclient.jar file is located in the \interclient directory. The Deployment WizardThe Deployment Wizard assists you in preparing a program for deployment.
The Deployment Wizard does the following: Deploying resources and late-bound classes Note that the Deployment Wizard does not automatically know about dependencies on files referred to by strings in Java code, such as resources or classes referred to by their name in a string. To make sure that such files are included in your archive, be sure to add them to your project, then select them in the Deployment Wizard. This suggestion applies to resource files (such as images or audio), documentation files (.txt or .html), and classes that are referenced using Class.byName or Beans.instantiate.
Executing Your Java The Win32 and Solaris versions of the JRE (Java Runtime) both include programs to run your applications. JRE Executable - The jre tool invokes the
Java Runtime interpreter for executing Java applications. The syntax for the jre command
is: JREW Executable (Win32 only) - The jrew command is identical to jre, except that a console window is not invoked. The syntax of the jrew command is: jrew [ options ] classname <args> Even though a CLASSPATH isn't required, it is still recommended that you include one. For example, including a batch file to run your application, would look something like this:
In the CLASSPATH above, rt.jar is the runtime libraries needed to run Java applications, interclient.jar is included only if you are connecting to a Borland InterBase server. You include your application archive as well, whether it is in a .zip or .jar. Web Browsers To execute applications (called Applets) embedded within HTML, web browsers use their own VM (virtual machine). Listed below, is the APPLET HTML tag, used to display a Java applet:
Applet Version Specifics for Deployment JDK 1.02 or JDK 1.1 1. Build your Applet in JBuilder. Compile the project. For the purposes of these instructions, we will use an example of your project existing in jbuilder\myprojects\untitled1\untitled1.jpr, and your Applet1.java having the package name of untitled1. 2. Copy your HTML file to the target directory. For example, if your target computer is running the IIS web server, the directory to copy to would be something like: c:\inetpub\wwwroot\, and if your subdirectory is called "Test", then you would use a command like: copy c:\jbuilder\myprojects\untitled1\Applet1.html c:\inetpub\wwwroot\Test. 3. Copy your .class files to the appropriate subdirectory, based on their package’s name, of the location named in the CODEBASE tag. If you don’t do this, you get a cryptic error message from the AppBrowser, such as ClassFormatError. To continue the above example, let's say your Applet class is untitled1.Applet1, and your CODEBASE parameter in the APPLET tag is ".". You should use a copy command like this: copy c:\jbuilder\myclasses\untitled1\*.class c:\inetpub\wwwroot\Test. 4. If your Applet uses JBCL, be sure to copy the necessary JBCL and JGL classes to the server also. If your Applet uses a JDBC connection, then be sure that the JDBC driver client classes are there also. 4a. Specifying a name for the JDBC driver name parameter of borland.jbcl.dataset.ConnectionDescriptor( )causes an applet security violation. Alternatively, pass an empty string as the driver name, and preload the driver class as follows: Class.forName(jdbcDriverName); database.setConnection(new borland.jbcl.dataset.ConnectionDescriptor(jdbcURL, jdbcUserName, jdbcPassword, false, "")); 5. Load c:\inetpub\wwwroot\Test\Applet1.html in your Web browser as a local file for initial testing. 6. Test via the Web server, by loading the http URL that represents Test\Applet1.html in your Web browser JDK 1.1 only 1. Build your Applet in JBuilder. Compile the project. For the purposes of these instructions, we will use an example of your project existing in jbuilder\myprojects\untitled1\untitled1.jpr, and your Applet1.java having the package name of untitled1. 2. Run the Deployment Wizard, selecting the applet java file(s) and any necessary image files. To see them in the Deployment Wizard, add them to your project first. 2a Do NOT select the .jpr or any .html files. They should not be in your .jar file. 2b. If you leave JBCL and JGL excluded, you will need to deploy three .jar files in step 3. 2c. If you turn off the exclusion of JBCL and JGL, your archive will be larger, but will contain all the necessary .class files in a single .jar, and so you will need to deploy only the one .jar file. One way to get all the necessary JBCL images is to add the following two packages to the project: borland.jbcl.control.image and borland.jbcl.view.image. You could also add only selected images these packages instead. In this example, you could name your archive untitled1.jar. 3. Modify your HTML page to add an ARCHIVE parameter to the APPLET tag. The value of this parameter should be the name of the .jar file, or a comma-separated list of the jar files, that you created in step 2. For example: ARCHIVE="untitled1.jar, interclient.jar" 3a. If you deployed all of your .class files, including JBCL and JGL dependencies, into a single .jar file, use something like this: ARCHIVE="untitled1.jar" 3b. If you excluded JBCL and JGL, then you will also need to deliver the JBCL and JGL files, using an ARCHIVE tag something like this: ARCHIVE="untitled1.jar, jbclrt.jar, jgl.jar". Check the redistribution details in your license agreement to see exactly what you can redistribute. 3c. An intranet alternative to 3b would be to install the jbclrt.jar and jgl.jar files in the local classpath for the browsers that will be viewing your applet, and then just putting the applet jar file on the server. The parameter would then be just this: ARCHIVE="untitled1.jar" 3d. In any case, your CODEBASE and CODE tags would remain something like this: CODEBASE="." CODE="untitled1.Applet1.class" 4. Copy your HTML file to the target directory. For example, if your target computer is running the IIS web server, the directory to copy to would be something like: c:\inetpub\wwwroot\, and if your subdirectory is called "Test", then you would use a command like: copy c:\jbuilder\myprojects\untitled1\Applet1.html c:\inetpub\wwwroot\Test. 5. Copy your archive file(s) to the server location indicated in the CODEBASE tag. For example: copy c:\jbuilder\myprojects\untitled1\untitled.jar c:\inetpub\wwwroot\Test Note that since the archive already contains the structure for the untitled1 subdirectory, you do NOT place the archive file down in an untitled1 subdirectory, but directly into the directory indicated in CODEBASE. 5a If you are using step 3b, copy all of your archive files, including JBCL and JGL runtime archives, to the same location. 5b. If your Applet uses JDBC data connections, be sure to copy the appropriate JDBC client driver class archive (e.g. Interclient.jar) to the server. 5c. If you are using step 3c, copy your applet jar file to that location, and, separately, get your browser clients to all have the JBCL and JGL runtime archives listed explicitly in their classpaths. Check the browser(s) you will be using to see how this is done, or whether these archives may already be present in their delivered archives. For example, for MS Internet Explorer the local archives are listed under the registry entry: Hkey_Local_Machine/Software/Microsoft/Java VM 6. Load c:\inetpub\wwwroot\Test\Applet1.html into your Web browser as a local file for initial testing. 7. Test via the web server by loading the http URL that represents Test\Applet1.html into your Web browser. JDK 1.0.x Deployment for Older Web Browsers To maintain an existing applet, just be sure to stick with 1.0.x Java features. See suggestions below. To create a new Applet for JDK 1.0.x 1. Use File|New Applet to create the html and java files. 1a Select the option for Generate Standard Methods. 1b. Create any parameters needed. 2. In the java source for the Applet, do these things: 2a Remove the imports for borland.jbcl and java.awt.event stuff: import borland.jbcl.layout.*; import borland.jbcl.control.*; import java.awt.event.*; 2b. Remove the XYLayout instantiation and usage lines:
3. Develop your applet using only 1.0.x features. 3a Use only the components on the AWT tab of the palette. 3b. Use the default layout (Flow) for the applet, or use 1.0.x-style layout management. Do not use XYLayout at all. 3c. You will probably have to change all .add statements from something like this: this.add(button1, null); to something like this: this.add(button1); 3d. Use only properties whose setter and getter methods were already defined in JDK1.0.x. For example, in JDK1.0.x, java.awt.Button had a label property (setLabel, getLabel), so it would be safe to use that one in the Inspector. If in doubt, refer to some 1.0.x-version documentation to know what methods you can call in 1.0.x. 3e. Do not hook up events using the Events tab of the inspector (JBuilder's Inspector generates JDK1.1-style event mechanisms) Instead, use 1.0.x-style event handling only. 3f. In general, code your application by hand. The Designers and Wizards generate 1.1 code. 4. Compile your Applet. 5. You can test it initially in JBuilder/AppletViewer as you would a JDK1.1 applet. 6. The code generated by JBuilder from 1.0.x-compliant source should be compatible with 1.0.x virtual machines. As an additional precaution, and to verify that it conforms strictly to 1.0.x patterns, you could also compile it with a JDK1.0.x version of javac.exe and use the JDK1.0.x class libraries. 7. Deploy your Applet as .class files. Do not use the Deployment wizard, because 1.0.x browsers do not know how to read java archive files and don't recognize the ARCHIVE tag in HTML. Archive Formats Initially, .zip files was the first archive used to keep files together, and to shorten download time. Soon after, Sun saw fit to create a standard for Java class distribtution. What is JAR? JAR stands for Java ARchive. It's a file format based on the popular ZIP file format and is used for aggregating many files into one. Although JAR can be used as a general archiving tool, the primary motivation for its development was so that Java applets and their requisite components (.class files, images and sounds) can be downloaded to a browser in a single HTTP transaction, rather than opening a new connection for each piece. This greatly improves the speed with which an applet can be loaded onto a web page and begin functioning. The JAR format also supports compression, which reduces the size of the file and improves download time still further. Additionally, individual entries in a JAR file may be digitally signed by the applet author to authenticate their origin. JAR is: JAR consists of a zip archive, as defined by PKWARE, containing a manifest file and potentially signature files, as defined in the Manifest and Signature specification. Changing the APPLET tag in your HTML page to accomodate a JAR file is simple. The JAR file on the server is identified by the ARCHIVE parameter, where the directory location of the jar file should be relative to the location of the html page: Note that the familiar CODE=myApplet.class parameter must still be present. The CODE parameter, as always, identifies the name of the applet where execution begins. However, the class file for the applet and all of its helper classes are loaded from the JAR file. Further note, that just as in Java programming, running Java applications or applets is no different. JAVA IS CASE SENSITIVE. This becomes important as you understand the JAR files mimic the directory structure on the users hard drive even if there were no archive at all. For example, below is a partial listing of a JAR file: To execute this application, you tell the web browser two things: About the manifest fileThe manifest file for a .jar file contains a list of files present within the archive itself, and includes information about some or all of the classes contained in that .jar file. The manifest file that is generated by the Deployment Wizard: The manifest file for any .jar must be named MANIFEST.MF and must be in the \META-INF subdirectory of the .jar file. The Deployment Wizard assumes that any file with a .mf extension is a manifest file. All manifest files in a project will be added to the Manifest File choice control of the Deployment Wizard. By selecting one of the .mf files in this list, you have indicated to the Deployment Wizard to rename that file to MANIFEST.MF and place it in the \META-INF directory in the target .jar file. This feature allows you to manually edit the manifest file that is to be included in an archive. If you have not specified a manifest file in this manner, the Deployment Wizard will
generate a manifest based on the files that you have selected to be deployed. The
generated manifest file can be found only in the target .jar file. If you wish to use the
manifest file for other deployments, extract it using the If you are unfamiliar with manifest files, you should allow the Deployment Wizard to generate a new manifest file each time a deployment archive is created. See Also: Which Archive Format Should I Use? So the question remains, which should I use? The answer is obvious, since Sun created the JAR format exclusively for class distribution, as well as supporting classes, it is the one to use. Installation Programs Realistically, .zip or .jar files are sufficient to distribute applications of any size. But one caveat of platform independence, is the inherent differences in each platform, and each Java virtual machine (often referred to as the Java VM). The InstallShield Software Corporation created an installation program for Java applications (which is in fact itself, written in Java). The main draw to this form of distribution, is that InstallShield allows you to target particular virtual machines. Some platform specific options include creating desktop icons and updating the registry on Microsoft operating systems. Non-platform specific options include displaying README files and license text. Upon finishing a few questions in the InstallShield wizard, you will have a single class which has everything you are distributing. The user has only to execute the class, and InstallShield will decompress and install your application. If the installation program doesn't find the targeted virtual machine, it will indicate the necessary VM, and exit. JDBC driver deploymentDuring the development of a Java program that accesses database information through a JDBC driver, you will need to obtain appropriate JDBC driver(s) for the database(s) your program will access, and deploy the driver(s) with your program. During applet development on your local machine, (when the browser is loading the classes from your local drive), and perhaps for your application or bean database access, you can use the JDBC-ODBC bridge from JavaSoft. However, this driver is not portable. Worse yet, for applet deployment, the security model of web browsers will not allow you to use this configuration when the applet is being downloaded from an HTTP web server, because the classes will not be allowed to access the native code in a local JDBC-ODBC.dll. For this reason, you must obtain an all-Java client-side JDBC driver before deploying your applet to an http server. This JDBC driver class will need to be deployed to the http server and downloaded with your applet. You will probably want to use all Java JDBC drivers for applications and beans as well. Examples of all-Java JDBC drivers are: Sun maintains a list of JDBC drivers at http://www.javasoft.com/products/jdbc/jdbc.drivers.html. JBDC drivers are generally referenced in source using the Deploying DataGateway Note: If you are using the Developers Kit, you cannot deploy applications or applets. Depending on your development needs, you must purchase the Professional or Enterprise versions of DataGateway to legally deploy applications or applets. For more information on DataGateway versions and licensing, you'll find additional information on the DataGateway home page at /datagateway/. Before You Deploy Before you deploy either an application or applet, make sure you have done the following: Note: You cannot use the Bridge in your distributed applications or applets, you must use the Client and Server. Deploying Applications If you have followed the steps outlined in "Before You Deploy," you are now ready to distribute your application. Users must have a Java VM that supports JDK 1.1 and an active TCP/IP connection to run the application. Deploying Applets After following the steps outlined in "Before you deploy," create or open an HTML file and add an <APPLET> tag and any parameters required by the applet. To deploy an applet, the users require a JDK 1.1 compliant browser. Supported browsers include: Deploying with the Deployment Wizard To include the necessary files for DataGateway support, the Deployment Wizard needs to recognize the fact that you are using the DataGateway classes. To do this, you simply need to instantiate the class. For example, if you are using the broker, use the following line: Then remove the JDBC driver name from your connectionDescriptor. Build your application or applet and deploy it with the Deployment Wizard. Once it's done, check the .jar or .zip, and make sure you have an entry that looks something like this:
|
||||||||||||||
PASTE TEXT HERE |