« Avast, me hearties! TLAPD has returned! | Main| Rosh Hashanah - Happy New Year 5,767 »

Incorporating Java Libraries in Lotus Notes

QuickImage Category Show-n-Tell Thursday

Reason #276 why Julian Robichaux rocks...

On 09/20/2006, Devin Olson wrote:

Hey there buddy.
Sorry to bother you, but I'm having some difficulties grokking Java within Notes.
Specifically, I can't seem to figure out how to reference a Java library from a Java Agent.

Client version: 7.0.1

From Designer Client, I created a Java library called Utilities.java
The code for this library is as follows:

import lotus.domino.*;

public class Utilities extends AgentBase {

   public Document getConfigDoc(String configKey) {

     // returns a document from the Database Configuration view.
     try {
       Session session = getSession();
       AgentContext agentContext = session.getAgentContext();
       Database db = agentContext.getCurrentDatabase();
       View view = db.getView("DbConfig");
       Document doc = view.getDocumentByKey("DbConfig", true);

       if (doc == null) {
         System.out.println ("could not get the config doc!");
       } else {
         System.out.println ("got the config doc!");
       } // if (doc==null)
       return doc;
     } catch(Exception e) {
       e.printStackTrace();
       return null;
     } // try
   } // getConfigDoc
} // class Utility


I have successfully compiled and saved this library. I then created a new Java Agent called test_getConfigValue. The code for this agent is as follows (lines that reference the library are remmed out):

import lotus.domino.*;

public class JavaAgent extends AgentBase {

   public void NotesMain() {

     try {
       Session session = getSession();
       AgentContext agentContext = session.getAgentContext();

       // Utilities util = new Utilities();
       // Document doc = util.getConfigDoc( "DbConfig");
     } catch(Exception e) {
       e.printStackTrace();
     } // try
   } // NotesMain()
} // class JavaAgent


I want to incorporate the afforementioned Java library into this agent. So I followed the instructions from Notes Designer Help (copied below):

Using a Java script library you can define common classes that you can then access from any Java agent.

    To use a Java script library in a Java agent
  1. From the Java agent programmer's pane, click Edit Project.
       The Organize Java Agent Files dialog box displays.
  2. From the Browse box, select Shared Java Libraries.
  3. Select the library you want to include.
  4. Click Add/Replace File(s).
       The library displays in the Current Agent Files list.
  5. Click Ok.

(See the attached file for a screenshot).

So, I would guess that I should now be able to reference the Utilities class and it's functions from within my new Java agent. This, frustratingly, is the reason for my email. For some reason, when I click "OK" (step 5 above), my agent doesn't seem to get updated. That is, it doesn't show the library as "referenced" on subsequent clicks of the Edit Project button. Am I missing something (not so) completely obvious? Is this normal behavior? Do you have any ideas as to what may be causing my problem?...



Julian's response was quick, concise, and solved my problem exactly....

I ran into this exact same problem not too long ago:

https://www.nsftools.com/blog/blog-08-2006.htm#08-15-06

Good luck with the Java! If this is your first foray into it, it will drive you crazy at first, and after it all sinks in (may take a while) you'll start to really appreciate the language. But you'll pull your hair out for a time until that happens...


So, what have we learned from this?

Don't use periods in the name of a Java Library.........period.

Hope this helps!

-Devin

Comments

Gravatar Image1 - Its excellent example and now i cam able to access my java library files in my java code.

thanks,
logas.M

Gravatar Image2 - Thanks for all the nice things to say! Glad I had the answer, really. 2 months ago I would have been as confused as you...

And if nothing else, it's good Google karma to post this type of thing for others to find.

Search

Wowsers! A Tag Cloud!

Links

MiscLinks