How to use JADE within Applets

Author: Claudiu Anghel (

Date: April 22, 2003 

Java platform: Sun JDK 1.3.1_01 Windows 

JADE version 3.0b1 


The aim of this tutorial is to show how to use JADE within applets. Since JADE is written in Java, it is quite easy to use the JADE technology in applets. The use of applets may be helpful in situations in which the client of a JADE based application doesn’t want to install anything on his machine but wants to access the application directly via the web browser. To be more specific, an applet integrating JADE agents will offer the possibility for such agents to live on the client’s machine without them needing more than a Java enabled web browser to be installed on that machine.


This tutorial assumes the following:

  • You have basic knowledge of Java language and Java (jdk1.3.1_01) properly installed
  • You have basic knowledge of JADE framework and JADE (jade3.0b1 recommended) properly installed
  • You have a Java enabled browser(Java Plugin v.1.3.1_01) installed
  • You have the Jakarta Ant tool properly installed


There are mainly only two things you must do in order to get an applet, that uses JADE, working: create a jar archive containing all your classes and sign this archive using a certificate. The certificate can be obtained from a well-known Certificate Autority (CA) like VeriSign or Thawte, but during the development, this certificate can be generated easily, as we will see during this tutorial. The steps that have to be followed are:

  • Generate a testing key pair.
  • Export a self-signed certificate(or get a real certificate from a well-known CA).
  • Import certificate in the Java Plug-in if the Java Plug-in is 1.3.0_01 or greater, or else import the self-signed certificate using the web browser(s) you’ll be testing on.
  • Create the jar archive (this may include the necessary JADE classes)
  • Sign the generated jar archive.
  • If the generated jar file includes only your classes and not the JADE classes then sign the JADE jar files too (i.e. jade.jar, commons-codec\commons-codec-1.3.jar, iiop.jar, jadeTools.jar, http.jar and so on)
  • Prepare the html file by adding in the archive attribute all the necessary jar files (the ones signed before)

The example associated to this tutorial shows how to use JADE in applets. The tested features are: creating an agent container within the applet, installing the HTTP MTP on the applet container, creating an agent within the applet container, exchange of messages between an applet JADE agent and another JADE agent living on another container, and migration of an agent to an applet container and from an applet container to another container.

JADE Applet Example description

The example has two main parts: the server part and the client applet part.
The server part performs the following:

  • Starts the JADE platform on a given port.
  • Creates a container and installs the HTTP MTP on this container.
  • Creates a server agent within this container.
  • The server agent waits for a message from another agent (the applet agent).
  • After receiving the message it creates a mobile agent. The mobile agent asks AMS where is the applet agent and moves to the applet agent container. After arriving in the applet container it moves back to the server container. Finally it sends a message to the applet agent and it is deleted by himself.

The client applet part performs the following:

  • Creates an applet and within this applet creates a JADE agent container after receiving the host name and the port for the main JADE platform.
  • Installs the HTTP MTP on the created container.
  • Within the container it creates an applet agent that sends a message to the server agent requesting the migration of a mobile agent.
  • The agent waits for a message and when the message arrives it is deleted by himself.

The example contains the following folder structure:

  • src – contains the Java sources organized in 3 packages: server(implementing the server, the server agent and its behaviour), mobile agent(implementing the mobile agent and its behaviour), client (implementing the applet, the applet agent and its behaviour)
  • lib – contains the clientapplet.jar file; in this folder the JADE jar files(jade.jar, commons-codec\commons-codec-1.3.jar, iiop.jar, jadeTools.jar, http.jar, sax2.jar) should be copied when running the example.
  • classes – contains the compiled classes
  • doc – contains the generated Java doc files
  • in the root the following files can be found: the ant build.xml file, some *.bat files for generating, exporting and importing a certificate, the startServer.bat file that starts the server and the clientJadeApplet.html that starts the client applet. 

How to run the JADE Applet Example

The following steps should be performed:

  • The JADE Applets example must be downloaded from the JADE download page
  • After downloading you MUST unzip the JADE Applets package under the root of the jade distribution tree. You should end having a hierarchy like jade/add-ons/jadeapplets.
  • Run the target copy-jade-lib from build.xml using ant tool – this will copy the jade.jar, commons-codec\commons-codec-1.3.jar, iiop.jar, jadeTools.jar, http.jar, sax2.jar from the JADE distribution to the lib folder.
  • Run the target jade-lib-sign – this will sign the JADE jar files
  • Run the target compile to compile everything in classes folder
  • Run the target applet-jar-sign to generate and sign the clientapplet.jar file
  • Run startServer.bat – this will start the JADE platform on the given port (the first parameter) and create the server container (with the HTTP MTP using the port given by the second parameter) and the server agent
  • Edit clientJadeApplet.html and fill in properly the host name of the jade platform, the port of the jade platform, and the applet container port.
  • Start clientJadeApplet.html 

You can also perform the following:

  • Generate your own certificate using keygen.bat, keyexport.bat, keyimport.bat
  • Use ant target compile to compile everything in classes folder
  • Use ant target applet-jar to generate the clientapplet.jar file
  • Use ant target applet-jar-sign to generate and sign the clientapplet.jar file
  • Use ant target applet-jar-signonly to sign the clientapplet.jar file
  • Use ant target clean to clean the classes folder and delete lib/clientapplet.jar
  • Use ant target clean-lib to clean the lib folder
  • Use ant target clean-all to clean the classes and lib folders
  • Use ant target doc to generate the javadoc documentation
  • Use ant target dist to generate the ditribution zip file 

Known Issues

  • On versions previous to JADE 3.0, moving an agent to an agent container created in an applet generates an error. This works fine in JADE3.0b1.