Deploying Java Programs
Preparing a project for deployment
Before you actually deploy your applet or application, there are some preliminary steps you should take to prepare your project so your program will work on another computer when deployed.
Rules for making a deployable application or applet
- Keep images in a subdirectory relative to your project (typically called images).
- Use only relative paths to refer to image files and other files used by your application or applet (for example, "images\logo.gif").
- Do not abbreviate the user-added classes with relative paths.
- If you access databases via JDBC, be sure your Database Connection properties specify the class name of the respective driver.
Rules for deployment
- Add all the files you use to your project using the Add to Project button
on the AppBrowser. This includes image files, text files and audio files.
- Use the Resource Strings Wizard to move your strings to a resource bundle. This is optional, but makes it easier to localize your application or applet for a different Locale.
- Make sure you have compiled your application or applet and have up to date class files.
- When deploying to an end-user, do not include the .jpr file in the deployed .jar or .zip archive file. The .jpr file is for development purposes only. If you deploy to another developer, and you don't work with the same directory structure, he will create a new project file on his machine to set the Class Path, Source Path, and Out Path to the correct place for his working environment.
- Create an install procedure that makes the necessary directories and sub-directories on the end-user's computer and places the files in those directories. This install procedure should also modify the Class Path value in the end-user's environment to specify the correct Class Path for finding the Java classes.
- Use the Deployment Wizard. This will create a .zip file or a .jar file in your default Out Path (for example, c:\JBuilder\myClasses) containing all your class files, image files, and other files named in the project. A .jar file is just a special form of .zip file, and it may be examined with WinZip32. Any directory structure under the project (such as an images subdirectory) will be preserved in the .jar file.
- Distribute your .jar file and explain that users will need to be sure this .jar file will be found using their Class Path. They will need to name the .jar file by name (for example, c:\JBuilder\myClasses\myApp.jar).
- Tell your users how to start your applet or application (for example, by double-clicking on an icon you've provided, or running a batch file at a Dos prompt , such as
path\jre classname
).
Note: For updated information on deployment, see JBuilder's technical publications web site at http://www.borland.com/jbuilder.
See also:
http://java.sun.com/docs/books/tutorial/TOC.html#APPLETS
Discusses basic applet considerations, including security.
http://java.sun.com/docs/books/tutorial/security1.1/index.html
Discusses general security API's and issues.
http://www.suntest.com/100percent/cpd/doc/cbook/cookbook.html
Discusses general portability and purity issues.
Creating an archive file
Once your applet or application is completed and ready to deploy, you will need a convenient way to compress and bundle the class, image, and audio files into one easily deliverable file. The best way to do this is to create a .zip file, or a .jar (Java ARchive) file, which is a zip file containing all the project files, plus a manifest file and potentially signature files, as defined in the Manifest and Signature specification.
To create an archive file,
- Open the project you wish to archive.
- Compile your project to create the class files.
- Choose Wizards|Deployment Wizard.
- Select the files to deploy. Also specify if any of the dependency files should be included in the .jar file.
- Choose what kind of archive file to create (.zip or .jar) and where it should be put.
- Click the Finish button when you are done.
If you selected .jar as the type of archive file, the Deployment Wizard creates a manifest file called manifest.mf in a meta-inf subdirectory of the .jar file. It also creates a copy of this manifest file named after the project name, and puts it into a meta-inf subdirectory in your project.
About the manifest file
The 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,
- Contains information about whether or not each class is a JavaBean.
- Contains information only about the classes that are actually in the project.
- Does not contain references to classes that are in the project as part of a package.
- Does not contain references to dependency classes.
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. If a file with the extension .MF is selected as a file to be deployed and you have selected a .jar as the archive type, the Deployment Wizard assumes that this is the manifest you want to use and will rename it (if necessary) and place in the correct location in the .jar file (meta-inf\manifest.mf).
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. This generated manifest will be named <project file name>.mf and then will be saved in the meta-inf subdirectory immediately under the project file (.jpr). For example, if you have launched the Deployment Wizard on the project c:\JBuilder\myprojects\deploytest\deployer.jpr, the manifest for the .jar would be saved as c:\JBuilder\myprojects\deploytest\meta-inf\deployer.mf.
The Deployment Wizard will not automatically add the manifest file to the project, but you can manually select and add the manifest file to the project.
If you are unfamiliar with manifest files, you should allow the Deployment Wizard to generate a new manifest file and overwrite the old manifest file, each time a deployment archive is created.
See Also:
Manifest and Signature specification
JAR files
The just-in-time compiler
AppAccelerator 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.
See Setting environment variables for command-line tools in the JBuilder User's Guide.
See also:
The Deployment Wizard
The Applet Wrapper Wizard