We help IT Professionals succeed at work.

Step by Step for writing a Java Method in a Lotus Client

Jaziar
Jaziar asked
on
Medium Priority
298 Views
Last Modified: 2013-12-18
This question has been asked before, but I was side tracked on a differnt project.  So now I am needing to be able to get this to work.

1.  I want to run an agent that will parse a jar file sitting on the server.  
2.  The jar file gets information from a differnt system and return values.  
3.  I want to take those values and create new documents.

Is writing a Shared script library /new java library the way to do this?  If that is the case, I need to figure out a way to include(setup) a class path?
can you do something like that with Lotus Script?  or Java Script?  

If the jar file is sitting on the same server as the nsf file, is that considered local?
Comment
Watch Question

Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Parse a jar-file? Or is it XML?

State your business requirements first, we can dive into the design details later on.

Author

Commented:
It is a executable jar file.

Basically, I am wanting to get part infomation from a differnt system.  I want to have a agent runs every 15 minutes that goes and queries the other system (jar file has query) return the information to notes, notes will create a document for each part.
Groupware Consultant
CERTIFIED EXPERT
Commented:
The jar-file is fixed, it contains one or more classes with methods? Basically, you want to create and use objects as defined in the jar-file? Or is it a Java executable, that runs in a command-screen, with
    Java -jar yourprog.jar
and you want to use the output?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Yes - fixed with class and method
Yes - I want to create / objects in defined in the jar fil
It is not a executable that run in the command-screen.
Yes - I need to be able to use the output.
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Do you have the interface to the classes defined in the jar-file? Is there a Java test program you can use as an example? Documentation etc?

My first approach would be to create a small agent that just creates an object from a class in the jar-file. That's the biggest hurdle.

Author

Commented:
Is there a Java test program you can use as an example?

Do you mean code?  I can show you the test java program

Author

Commented:
this is the test java code

package com.company.apps.lotusquery;

import matrix.util.Version;


public class EBOMQuery {

    public EBOMQuery() throws Exception {
    }
   

    /**
     * !! The actual functionality here is only a stub for prototyping !!
     * Returns a list of parts, in tab-delimited format, contained within
     * the specified EBOM.  The EBOM is specified by the top-level part
     * name.  The latest revision of the specified EBOM will be retrieved.
     * @param   ebomName    the name of the top-level part for this EBOM
     */
    private String getTabDelimEBOMPartList(final String ebomName) throws Exception {

        /* Use a class from the eMatrixServletRMI.jar file */
        Version version = new Version();
        System.out.println("Application: " + version.application + "\nVersion: " + version.number + "\n");

        String tdpl = "Arm\t3000895\tA\t35004.36845.11282.30693\nGear\t3000954\tA\t35004.36845.15714.59706\nSensor\t3000883\tA\t35004.36845.14669.476\n";
        return tdpl;
    }


    public static void main(String[] args) throws Exception {
        EBOMQuery ebomQuery = new EBOMQuery();
        String tabDelimPartList = ebomQuery.getTabDelimEBOMPartList("3000440");
        System.out.println(tabDelimPartList);
    }

}

Author

Commented:
Do you mean interface documentation?  If so, then yes, we have Java Docs that list all of the packages, classes, and methods in the jar file.
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Ah, great! That should mean that you could try some code on your PC, in a client agent or so.

Your first attempt might be to create a Java agent and run it. Just the default agent content would do, I think.

Then add the lines
    package com.company.apps.lotusquery;

    import matrix.util.Version;

to the agent, and compile it. The jar-file should have been copied to some directory that can be found by the Designer. Or add it to the CLASSPATH in the environment settings of your PC.

Once you get that done, you're at 60%...

Author

Commented:
Will the designer be able to find the jar file if it is setting on the same server as the nsf file?
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Let's first try to make this work on your PC, if that's at all possible. In a later stage (you wanted it step by step, didn't you? ;-) we could try the agent (tested and working on your system) on the server. But you're right, you'd have to place the jar-file on the server as well, also in a directory the server can find (e.g. using the CLASSPATH environment variable).

Author

Commented:
Since users are using this database. I had the jar file placed on the same server as the notes .nsf file.  Is there a way in the client to set the class path?

Author

Commented:
import matrix.util.Version; Allways errors here - says class not found on import
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
In order to test it on a client, everything must be present on the client! Java compilation is also done locally. The classpath MUST be set on the local system as well, in the configuration somewhere (as it used to be in autoexec.bat). It should be in the Configuration settings, System, Advanced, Environment variables.

I suppose matrix.util.Version isn't required for the test, so try only with the package.

Author

Commented:
Good Morning Bosman

Here is my question.  My client is indeed sitting on my local machine, but the database that I am working in, is sitting on a server.  Do I need to do this testing on a local database?  I did add the path to the jar in my local Enviroment settings.  I will remove the matrix.util.Version and try to recompile.

Author

Commented:
After removing the above, this compiles fine


package com.company.apps.lotusquery;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

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

                  // (Your code goes here)

            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Good! Now try this:

package com.company.apps.lotusquery;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

     public void NotesMain() {

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

               EBOMQuery ebomQuery = new EBOMQuery();
               String tabDelimPartList = ebomQuery.getTabDelimEBOMPartList("3000440");
               System.out.println(tabDelimPartList);

          } catch(Exception e) {
               e.printStackTrace();
          }
     }

    /**
     * !! The actual functionality here is only a stub for prototyping !!
     * Returns a list of parts, in tab-delimited format, contained within
     * the specified EBOM.  The EBOM is specified by the top-level part
     * name.  The latest revision of the specified EBOM will be retrieved.
     * @param   ebomName    the name of the top-level part for this EBOM
     */
    private String getTabDelimEBOMPartList(final String ebomName) throws Exception {

        /* Use a class from the eMatrixServletRMI.jar file */
        Version version = new Version();
        System.out.println("Application: " + version.application + "\nVersion: " + version.number + "\n");

        String tdpl = "Arm\t3000895\tA\t35004.36845.11282.30693\nGear\t3000954\tA\t35004.36845.15714.59706\nSensor\t3000883\tA\t35004.36845.14669.476\n";
        return tdpl;
    }

}

Author

Commented:
EBOMQuery ebomQuery = new EBOMQuery(); errors -> class not found
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Excuse me 1000 times. I made several big mistakes in the code and we proved nothing at all (except that my Java isn't very good...).

Firstly, the code doesn't seem to be a test program. The program itself is called EBOMQuery so it references nothing from the jar-file. Do you have a real test program that you can compile and run with Java? Or can you find, in the documentation, some class you can create an object from?

Author

Commented:
Question

My client is running on my computer
The Database is setting on a server
My Jar File is setting on a server
My Java code in setting in the database on the server

Where is the java?  When I click the compile button, where is the java running?
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
If YOU click on a button, the code that's running is on YOUR computer, even if the database is on the server. That's what client-server computing is all about.  Therefore, the jar-file must also be on YOUR computer, in such a place that it can be found by the Notes-client.

So, it would be the easiest way to install everything locally, maybe even the database (either a local replica or a local copy, just for testing purposes). If necessary, you can have a look in the jar-file with a utility like WinRAR, so you can find out what the structure of the classes in it is.

Author

Commented:
I have tested about 3 java programs.  They all compile and work.  

example

import lotus.domino.*;
import java.util.Vector;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

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

                  Database db = agentContext.getCurrentDatabase();
                  Document memo = db.createDocument();
                  
                  // set the field values
                  memo.appendItemValue("Form", "A Person");
                  memo.appendItemValue("Subject", "You've Got Mail");
                  RichTextItem body = memo.createRichTextItem("Body");
                  body.appendText("Here is the attachment:");
                  body.addNewLine(2);
                  body.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, "c:\\autoexec.bat", "autoexec.bat");
                  
                  // add all the recipients you want
                  Vector v = new Vector();
                  v.addElement(session.getUserName());
                  v.addElement("Someone Else");
                  
                  // and send it off
                  memo.send(true, v);

            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}

So I am guessing the next step is I need to make sure I can see the jar file on my local system from the client.
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Indeed. The easiest way is to find out if the thing compiles with just one reference to a class in that jar-file. So: get your documentation or a test program, and find out where the first object is created that is based on a class in the jar-file. Try to create a similar object, only the creation, and nothing else.

Author

Commented:
I have a java program (agent) that is using the jar file on the server.  If my Java program writes the output to a flatfile, how do I know where the file goes?
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
If it's a scheduled agent that runs on the server, the output will also be written in a file on the server. I think...
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Found this somewhere:

To tell Notes where the Java classes are, include the following line in your Notes.ini file:
    JavaUserClasses = <classpath1>;<classpath2>; ... <classpathn>

For example, if the Java classes are in one directory, such as E:\LSI\test\java, the Notes.ini file would include the following line:
    JavaUserClasses=E:\LSI\test\java

Author

Commented:
I think this problem has been answered, I am now working on the Java code
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Well done! And thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.