A ZipClassLoader for automated application distribution - JavaWorld April 2000
Tutorial Details:
A ZipClassLoader for automated application distribution
A ZipClassLoader for automated application distribution
By: By Kevin Pauli
Learn how to use ClassLoaders and exploit the zip library
ome developers consider application maintenance an afterthought. Naturally, you tend to focus on the task at hand, which is, first and foremost, to make your program work! Sure, there might be a few minor bugs here and there, but you can always fix those in the next maintenance release, right? And no, you didn't have time to include every bell and whistle your users requested, but you can include those features in a subsequent release. When you start thinking along these lines, your project needs a maintenance plan, and the sooner the better.
For a recent Java project at IBM, my team was forced to consider application maintenance from the start. The situation had an interesting set of characteristics: First, the users were mobile and needed disconnected access to the application. Second, the users were dispersed worldwide. Third, the application was expected to evolve quickly. And fourth, the department had limited support resources to help users install upgrades.
Because the users were mobile, we needed to install the application locally on the their laptops, rather than having them retrieve the latest bytecodes from a server. Because the users were worldwide and frequent updates were expected (not to mention that we had a small support infrastructure with a limited travel budget), we needed a reliable means of remotely updating the application. We wanted something more seamless than an email with an attached jar file and installation instructions, or an executable packaged with InstallShield. The solution we implemented, which solved our problem nicely, was to store the application bytecodes in the same database the users replicate for the application data. We installed on everyone's workstation one jar we termed the bootstrapper. This unchanging piece of code locates the local database, loads the application-specific bytecodes, and launches the application. When the developers add a new report or fix a bug, we recompile the bytecodes and replace them in the database on the server. The next time users replicate their local database with the one on the server, they receive the new bytecodes along with the other new application data.
What makes this dynamic approach possible is the Java ClassLoader . A ClassLoader is the part of the JVM responsible for finding classes as your application instantiates them. Thanks to the foresight of the Java creators, you can replace the default class loader with one of your own, which loads classes in just about any way you can imagine. Any array of bytes can be interpreted as a class that your program may instantiate at runtime. The bytes may come from files in the local machine or from a server halfway around the world, delivered via a network connection. In our case, we put the bytes into a Lotus Notes database. For convenience, and to minimize the amount of replicated data, we packaged all application-specific files into a compressed zip file. The java.util.zip package lets users read and write files in the zip format.
Meet the players
In this article, I show you how we designed and developed the infrastructure for our application deployment. The components should be reusable for your own applications. Here is a brief preview of each component, which I then describe in more detail:
The BootStrapper : The class com.paulitech.bootstrap.BootStrapper is the main class we installed on the users' workstations to let them receive the dynamic application updates. It takes, as command-line arguments, the location of the database and the class to instantiate.
The Bridge : Our application at IBM happens to use Lotus Notes as the database, but yours may use something else. To decouple the choice of database from the rest of the application, I've used a common design pattern known as a bridge (as documented in Design Patterns , by Erich Gamma, et al., see Resources ). All access to the database is via the abstract interfaces defined in com.paulitech.bridge . The Lotus Notes-specific implementation of the bridge interface is in com.paulitech.bridge.notes . If your database is something other than Lotus Notes, you will need to create your own bridge implementation. The interface is rather small and simple, and this task should not take long for an experienced JDBC programmer.
The ZipClassLoader : This is our custom ClassLoader , located in com.paulitech.classloader.ZipClassLoader , which extends java.lang.ClassLoader , the default class loader. Its constructor is passed an array of bytes, retrieved from the database, that represent the zip file. When you need a class, you ask the ZipClassLoader for the class by name. The ZipClassLoader handles all the ugly details of retrieving the proper array of bytes out of its zip file. To the outside world, the ZipClassLoader acts just like the ClassLoader that it extends. This essential component is delivered along with the BootStrapper to the users.
The FileInstaller : Of course, you need a tool to actually put the zip file into the database so that it may be replicated. com.paulitech.classloader.BridgeFileInstaller is an abstract class that talks to the Bridge database interface described above and writes records to it. The com.paulitech.classloader.notes.NotesFileInstaller is a concrete implementation of the BridgeFileInstaller , which, naturally, uses a NotesBridge . If you are using something other than Lotus Notes for the database, you should create your own installer tool implementation, subclassing BridgeFileInstaller , as I have done for the Notes case.
Grab on to your bootstraps
Below is a class diagram depicting what happens on the user's workstation. There's quite a bit of code, so rather than go through it line by line I will describe the algorithms with prose. The full source is available in the sample file (see Resources for a download). At this point, it would be a good idea to follow along with the source code.
Figure 1. Class diagram depicting the BootStrapper and related classes
A batch file ( bootstrap.bat , in the example) kicks off the main() routine in the BootStrapper class, passing it the database location, the key that identifies the particular record that contains the bytes of interest, the name of the class you wish to instantiate as the main class, and the prefixes of any application-specific classes (separated by commas). For example, if you work for Widgets USA, all your application-specific classes start with com.widgetsusa , and you've included some custom libraries written by a business partner named Gunkle Media, whose classes are all under com.gunklemedia , this fourth parameter to the Bootstrapper should be com.widgetsusa,com.gunklemedia . The reason this last parameter is necessary is somewhat obscure, and it is necessitated by something that took me a great deal of hair-pulling to figure out. I'll explain more when I discuss custom class loaders.
Bridge over troubled data
Armed with the parameters, the BootStrapper can go to work. First, it creates a NotesBridgeFactory , which is a concrete implementation of an abstract BridgeFactory class. The BridgeFactory , as you might guess from the name, is responsible for generating a Unified Field Theorem. Just kidding! As the name suggests, its sole purpose is to create Bridge objects. What is a Bridge object? A Bridge provides an abstract mechanism for getting data in and out of your system. The core system does not actually care how the data is transferred, just that it does. The data could be going in and out of a database, could be sent and retrieved via a message queuing system, or could be transcribed by human operators onto scraps of pigeon-delivered paper. The point is, your core application talks to something that adheres to the Bridge interface and doesn't worry about the details. In this particular case, the data is ultimately stored in a local Lotus Notes database that the users replicate periodically with a server. The vagaries and peculiarities of the Notes API (and there are many, trust me!) are hidden behind the abstract interface. This allows you to change the data transport at a later time with minimal impact on your existing code.
The Bootstrapper can ask the BridgeFactory for an instance of a Bridge that corresponds to the key passed in. In this example, the file you're interested in is exampleapp.zip . The BridgeFactory (actually implemented as a NotesBridgeFactory ) goes off to the Notes database and attempts to find a document (NotesSpeak for record) that matches that key. When it finds that record, it creates a Bridge (actually implemented as a NotesBridge at runtime) corresponding to that record and returns it. The Bootstrapper , using the getPayload() method of the Bridge interface, grabs the string representing the contents of the file. Notice I said "string," not "array of bytes." In a perfect world, Notes would handle raw streams of bytes better, but since Notes was designed as an unstructured document database, it does not support pure binary data. You can turn arbitrary arrays of bytes into strings and back again via old-fashioned base-64 encoding. I was able to steal -- ahem, reuse -- some nice base-64 encoding classes from org.w3c.tools.codec .
Zipping right along ... with a load of class!
So, after the Bootstrapper gets the string from the Bridge and decodes it, you have an array of bytes that represent a zip file. Now what? How do you retrieve the classes and instantiate them? The Java runtime environment (JRE) loads new classes and instantiates them via a ClassLoader . When you start the JRE and load your initial class with the main() method, it creates a ClassLoader known as the primordial class loader, which loads your class. Any subsequent classes referenced by that class will use the same ClassLoader that loaded it. Thi
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: A ZipClassLoader for automated application distribution - JavaWorld April 2000
View Tutorial: A ZipClassLoader for automated application distribution - JavaWorld April 2000
Related
Tutorials:
|
Displaying 1 - 50 of about 1786 Related Tutorials.
|
Open Source Automated Test Tools written in Java
|
Open Source Automated Test Tools written in Java
|
The Distribution Release of VLOS 1.2.1
The Distribution Release of VLOS 1.2.1
The Distribution Release of VLOS 1.2.1
The developers of VLOS (formerly... distribution
based on Gentoo Linux.
== Introduction ==
VLOS 1.2.1 Project |
Free Linux Distribution in India
Free Linux Distribution in India
Free Linux Distribution in
India
 .... We are providing Free Linux CDs in
India. Our Linux Distribution |
JFreeChart - An Introduction
java chart library.
David Gilbert founded the JFreeChart project in February 2000... in swing and web based
application by JFreeChart. JFreeChart provides many |
Open Source Application Server
Open Source Application Server
Open Source Application Server
New Open-Source Application Server
A new open source application... regarded Sri Lankan firm of open source developers. It's Tungsten 1.0 application |
Rich Internet Application
Rich Internet,Rich Internet Application,Rich Internet Application... With
Rich Internet Application
 ... interface to the Web client while rest of some remain on
application server |
Apache Geronimo Application server Tutorial
JavaEE( or J2EE, old name) application server. It is so much capable that it can... JavaEE application server which uses Industry respected and Industry proven... costs you a penny.
It is a J2EE 1.4 certified application server, however |
Introduction to Apache Geronimo application Server
Geronimo
Introduction to Apache Geronimo application...;
Apache Geronimo application server is fully JEE
certified open source application server in the market. Apache Geronimo project
uses best open source |
GUIdancer
;
GUIdancer is a powerful
Eclipse-based tool for the automated testing of Graphical User... in
the application under test.
Advanced observation mode
Multi-user... method which allows test specification to begin even before the
application under |
Aldon Application Lifetime Management Suite
Aldon Application Lifetime Management Suite
Aldon Application Lifetime Management Suite
 ... to the IBM Rational Application
Developer for WebSphere Software (RAD |
Yoxos Eclipse Distribution
Yoxos Eclipse Distribution
Yoxos Eclipse Distribution
  |
Struts 2 Hello World Application Example, Learn how to develop Hello World application in struts 2.
Struts 2 Hello World,Struts Hello World,Developing Hello World
Application...
Hello World Application
 ... Hello World
application based on Struts 2 Framework. Our Struts 2 Hello |
The Distribution Release of GRML 0.6
The Distribution Release of GRML 0.6
The Distribution Release of GRML 0.6
Latest version of grml 0.6 is
released and available for download.
grml is a bootable CD (Live-CD) based |
Easy Eclipse Plugin
prepackaged for you to add to
an EasyEclipse
Distribution. An EasyEclipse Plugin may work with a non-EasyEclipse
distribution of Eclipse, but we have not tested..., so it
may easier to install the Server
Java distribution.
Eclipse
J2EE tools |
RoseIndia.net Is Your On-Line Linux & xBSD CD Distribution Source
RoseIndia.net Is Your On-Line Linux & xBSD CD Distribution Source
Debian Linux CD's
Now Available Debian 3.0 r2 i386 CD Set... governs the distribution of any
"open source" Linux OS Distribution |
RoseIndia.net Is Your On-Line Linux & xBSD CD Distribution Source
RoseIndia.net Is Your On-Line Linux & xBSD CD Distribution Source... which governs the distribution of any
"open source" Linux OS Distribution.
  |
Linux Distributions
;
Definition
The Linux distribution... distribution is easily available at free of cost without technical support... be downloaded from various iso-image
distribution of Linux Vendors' website either by paying |
EasyEclipse for Ruby and Rails
;
There are currently 9 comments for this distribution. You can review them and add more here.
Composition
This distribution includes... Java application on Sun Java(tm) runtime, packaged for
Eclipse use. (Windows |
EasyEclipse for Python
;
There are currently 10 comments for this distribution.
You can review them and add more here.
Composition
This distribution includes... application on Sun Java(tm) runtime, packaged for
Eclipse use. (Windows only)
Java |
Database books Page12
to prepare for and run an installation on a Windows NT, Windows 2000, Solaris, AIX... and exit points that connect a source or target application data with any one... with the following application servers: Sybase EAServer, IBM WebSphere Application Server |
rPath Linux 0.99.6 (Beta) has been released now
is a Linux distribution built with the new Conary distributed software management... and distribution development experience, to automate many of the tasks that have made... software that is easily tailored to suit unique application needs. rPath Linux |
RR64 Linux 3.0 Beta 1 has been released
Linux is the world's most complete GNU/Linux distribution based on Gentoo unstable... and customized for just about any application or need. Extreme configurability... most complete GNU/Linux distribution based on Gentoo unstable. Flexibility |
Web Application
Web Application
Web Application
Web Application is an application which is stored on the web
server and delivered over the www or internet. Web Application is vary popular |
Buy Peanut 9.6 Linux in India from us. Peanut 9.6 distribution is available in India.
Buy Peanut 9.6 Linux in India from us. Peanut 9.6 distribution is available... for those new to Linux. This is the most POWERFUL and FUN distribution yet... it now. Details of the Peanut 9.6 Linux Distribution:
Sr |
Running the application
Running the JSF Rich Faces Application,How to Run JBoss JSF Login and Registration Application
Running the Application...;
If you have completed previous steps of the application |
Login Application
Login Application,Struts Login Application,Hibernate Login
Application,Hiberate Login
Login Application
 ...;
This tutorial provides some simple steps for creating a website login
application |
Compiling and testing the application
Compiling and testing the application
Compiling and testing the application
 ...;
In this application we |
Compiling and testing the application
Compiling and testing the application
Compiling and testing the application
 ...;
In this application we |
Application Server
Application Server
Application Server...;
WAST
WAST (Web Application Server Toolkit) is a framework for developing web application server adapters. It contains core and UI |
Download Quartz Job Scheduler
Quartz Job Scheduler from its distribution
web site and then create development... for the development of Job
Scheduling application in java. Quartz Scheduler is from... for the development. In the next
section we will develop a simple scheduler application |
JSF Simple Login Application
JSF Simple Login Application
JSF Simple Login Application
 ...;
This is the login application in which |
Simple JSF Hello Application
Simple JSF Hello Application
Simple JSF Hello
Application
 ... to follow to create own JSF
application. In this example we will explain all you need |
Struts 2 Login Application
Struts 2 Login,Struts 2 Login Application,Struts 2 Application
Struts 2 Login Application
 ...;
Developing Struts 2 Login Application |
Java Programmers with Financial Application
Java Programmers with Financial Application
Java Programmers with Financial Application
 ...;
You will be working on challenging Financial application:  |
Simple Bank Application in JSP
Simple Bank Application in JSP
Simple Bank Application... application
in jsp . In this application user can Update the User Profile, Cash... transaction report for particular time period. We run this Bank Application |
JSF Validation In Login Application
In Login Application
 ... gives you the best approach for the login
application. You have learnt about the login application without validating the
application. But in this section you |
Application Servers for Java
Application Servers for Java,Application Servers in Java
Application Servers for Java
 ... have collected the list of all the application servers available for running java |
Developing database for the application
Application
Developing Database for the Application... for this application. The name of the table is "register"
under... - 5.0.19-nt : Database - application |
Application of Bioinformatics in various Fields
Application of Bioinformatics in various Fields
Application of Bioinformatics in various Fields....
It is the comprehensive
application of mathematics (e.g., probability and statistics), science |
Web Application Directory Structure:
Web Application Directory Structure,Servlet Directory Structure,Java Web Application Directory Structure
Web Application...;
To develop
an application using servlet or jsp make |
Web Application Directory Structure:
Web Application Directory Structure,Servlet Directory Structure,Java Web Application Directory Structure
Web Application...;
To develop
an application using servlet or jsp make |
Open Source Installer
suitable for internet distribution.
Being a user's first experience with your... goodies. This distribution contains valuable, up to date, Open Source software... as single executable files for easy distribution over the web and handle |
Simple input application in Echo3
Simple input application in Echo3
Simple input application in Echo3
 ...;
In this sample server-side application |
Features and Limitations of the Application
Features and Limitations of the Application
Features and Limitations of the Application
 ... of the application are as follows :
This application is used |
Forgot Password Screen of Application
Forgot Password,Struts Hibernate Forgot password form
Forgot Password Screen of Application
 ... Screen our web application allows the user, to request for
their forgotten |
Server Side Application
Server Side Application
Server Side Application...;
Server side application is used to get.... And this application is also used to
maintain the list of users and broadcast this list |
Deploying Hello World Application on Apache Geronimo Application Server
Apache Geronimo Hello World Application Test, Deploying Hello World Application on Apache Geronimo Application Server
Deploying Hello World Application on Apache Geronimo Application Server
  |
Creating Midlet Application For Login in J2ME
Creating Midlet Application For Login in J2ME
Creating Midlet Application For Login in J2ME
 ... show to create the Midlet application for user login . All
Midlet applications |
History of web application
History of Web Application,
History of web application
 ...;
Earlier in client- server computing, each application
had |
|
|
|