dev.kanngard.net make sure you visit my new blog at: johankanngard.net

Creating Domino agents with Netbeans

by Johan Känngård / [Java] / 2002-02-03 / #8


Introduction
Netbeans is an open source IDE, that is created and executed in a Java environment. It is a flexible and powerful IDE, and if you are tired of the lack of debugging capabilities for Java in the Lotus Domino Designer client, you may want to look at Netbeans. In this short tutorial, I will try to explain how you can set up your environment, to allow you to create, debug and run your agents from Netbeans.

Before we start
To follow the tutorial, you will have to download the latest version of Netbeans, that was version 3.3 when this article was written. Please refer to the Netbeans documentation on how to install it. I assume that you have installed Lotus Domino Designer R5 and Lotus Notes R5. If not, please buy it, or download an evaluation copy from notes.net.

You also need the Java Development Kit 1.1.8 to compile Java files in the format that Domino / Notes uses internally, AND the Java Development Kit 1.3.x to be able to start Netbeans. In Lotus Domino Rnext, the Java Virtual Machine will be upgraded to 1.3x. There might be differences in platform specific things, like environment variables. This tutorial is aimed towards the MS Windows 2000 platform.

Configuring Agent Runner
The main subject when designing agents outside the Lotus Domino Designer, is the AgentRunner. The AgentRunner is a part of the Lotus Domino Java package, and allows external Java programs to communicate with Domino as if it were an agent. There is an AgentRunner database in the Notes data directory. This database is used to keep track of the AgentContexts we will create. Let´s head straight for the code!

import lotus.domino.*;

public class AgentRunnerTest extends DebugAgentBase {
   public void NotesMain() {
   }
}
AgentRunnerTest.java

Configuring Netbeans
To let Netbeans know about the Java-classes that we are about to use, we must mount a JAR file as a Netbeans filesystem.

Configuring JAVA_HOME environment variable
We also have to set up Netbeans to use the external JDK when compiling. This is because you can not run Lotus Domino agents that has been compiled with a JDK that is newer than version 1.1.8, and Netbeans uses JDK 1.2 or higher for internal compiling. There are two ways to set up Netbeans to use an external compiler. The first is to set the environment variable JAVA_HOME to the JDK 1.1.8 directory (i.e. c:\jdk1.1.8) and specify which class that should be compiled with the external compiler. The second is to configure Netbeans to use a specific javac program when compiling the Java class. The first is the simplest, so I will explain that here. If you know how to set up an environment variable, please skip this section.

One thing remains, and that is to tell Netbeans what source files to compile with the external compiler. I will come to this in a moment...

Our first agent
When all is configured, let us create an agent OUTSIDE of the Lotus Domino Designer!

public static void main(String args[]) {
   try {
      AgentRunner.main(new String[] {
         "AgentRunner Test",      // Agent name
         "AgentRunnerTests.nsf",  // Database
         "local"});               // Server
   } catch(Exception e) {
      e.printStackTrace();
   }
}
public void NotesMain() {
   try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      Database currentDb = agentContext.getCurrentDatabase();
      System.out.println("Current database: " +
            currentDb.getTitle());
   } catch(Exception e) {
      e.printStackTrace();
   }
}
Full source of the first agent, with some extra code: DominoAgentTest.java

Useful links
"Getting yourself ready to create servlets", an article at codestore.net, explaining how to create servlets for Domino in Netbeans.
Lotus Domino Toolkit for Java/CORBA, a must if you want to get all information about Java programming in Lotus Domino.
Apache Jakarta, an open source community for Java developers.
Lotus Developers Network, an informational site of developing in Lotus products.
Lotus Developer Domain, from the creators of Notes / Domino. Many useful sources, like discussions, documentation, tutorials, articles etc.
Sun Java Developer Connection, all documentation, discussions, tutorials etc. of the Java language.