Date tip published: | 06/20/2005 |
Description: | Often the developer will be given a Java class to interface with a Domino agent. One reason to use an external class is to provide functionality not available in the Java JRE provided in Domino 6 (1.3) such as regular expressions or XML processing. This tip shows three ways to use external Java classes in Domino agents. |
To learn more about how to use Java in Domino use the following links:
Beginner Java Programming for Notes Domino 6
Intermediate Java Programming for Notes Domino 6
Use External Classes in Domino Agents
Often the developer will be given a Java class to interface with. One reason to use an external class is to provide functionality not available in the Java JRE provided in Domino 6 (1.3) such as regular expressions or XML processing. This tip shows three ways to use external Java classes in Domino agents:
- Import the class into the agent
- Use a NOTES.INI parameter
- Copy the class to the jvm\lib\ext directory
There are advantages and disadvantages of each method which will be discussed in this tip as well as the procedure for each method.
Import the Class into the Agent
If the external class will be used in only one or two agents, then it can be imported right into the agent. This way the class will become part of the Domino database and will replicate to the other replica copies of the database. The advantage of this method is that it will work on all Notes clients and Domino servers once the database has been replicated to them. The disadvantage is that each agent will require the external class to be imported. This becomes a maintenance issue if the external class changes and needs to be updated.
Procedure - Import the Class into the Agent
External Java class files can also be included in your Domino Java agents. When you do this, all of the public methods in the included external classes are available to your agent.
Follow these steps to include an external Java class in a Domino Java agent:
- Click the [Edit Project] button at the bottom of the programmer's pane. This action opens the "Organize Java Agent Files" dialog window.
- In the Organize Java Agent Files dialog, choose to browse the "Local Filing System" and select the Java class to include from its location in the file system, as demonstrated in the image below. Click the [Add/Replace File(s)] button to add the selected Java class file to the "Current Agent Files" box on the right side of the dialog.
- Click the [OK] button to close the Organize Java Agent Files dialog and return to the Agent Builder window.
Many Java classes are deployed in Java Archive files (.jar files) or uncompressed Winzip files. These can also be imported using the procedure above.
The external classes can also be imported into a Java Script Library which will also become part of the database. If a Java Script Library is used than the Script Library will need to be imported into the agent that will use that external class by following the procedure above but choosing "Script Libraries" instead of "Local File System" for the Browse setting. This allows the external class to be used in multiple agents in the database without having to import the external class into each agent that uses it. Java Script Libraries can not be referenced from other databases so a Script Library will have to be created for each database that uses the external class.
Use the Notes.INI Parameter
If you want some specific Java functionality available to every agent on a Notes client or Domino server without having to include it, you can add a variable called "JavaUserClasses" to the NOTES.INI file. For example:
JavaUserClasses=c:\javaclasses; |
The Java class file is then copied to this location specified in the NOTES.INI parameter. Jar files can also be specified as in the following example:
JavaUserClasses=c:\javaclasses\ccprocess.jar; |
This will then allow that class to be used on every database on that computer without having to do the import procedure that was covered above. The disadvantage is that this setting will not replicate. The NOTES.INI file will have to be modified on every computer that will also have a copy of the database AND the java class files (or JAR files) will have to be copied over to each computer that will run the agent.
You must restart Notes/Domino after changing the NOTES.INI file for the changes to be recognized.
Below is the reference for this NOTES.INI parameter from Domino Administrator Help:
JavaUserClasses=list
Description: Allows code-sharing across agents and applets. The value list is a list of directories, JAR files, or ZIP files that are added to the Java Virtual Machine's internal classpath so that classes can be found via the system loader (rather than via attachment to the agent or applet). Note that this doesn't replicate and requires access to the file system on the server.
Use a semicolon (;) to separate list items for Win32 and OS/2 systems and use a colon (:) to separate list items for UNIX systems; for example, a valid list for Win32 is:
c:\classes;d:\appxyz\stuff.jar |
Copy the Files to the JVM\LIB\EXT Directory
Another option is to copy a JAR file to the jvm\lib\ext directory where the Notes or Domino program files are located. When Notes/Domino starts it will check this directory for any Java classes (Note: class files do not work with this option, it must be a JAR file.)
Like the NOTES.INI option, the files will have to be copied over to every Domino server (or Notes client) that will use these external classes. This will then allow the class to be used on every database on that computer without having to do the import procedure that was first covered above. |