Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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

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?
0
Jaziar
Asked:
Jaziar
  • 15
  • 13
1 Solution
 
Sjef BosmanGroupware ConsultantCommented:
Parse a jar-file? Or is it XML?

State your business requirements first, we can dive into the design details later on.
0
 
JaziarAuthor 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.
0
 
Sjef BosmanGroupware ConsultantCommented:
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?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
JaziarAuthor 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.
0
 
Sjef BosmanGroupware ConsultantCommented:
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.
0
 
JaziarAuthor 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
0
 
JaziarAuthor 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);
    }

}
0
 
JaziarAuthor 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.
0
 
Sjef BosmanGroupware ConsultantCommented:
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%...
0
 
JaziarAuthor Commented:
Will the designer be able to find the jar file if it is setting on the same server as the nsf file?
0
 
Sjef BosmanGroupware ConsultantCommented:
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).
0
 
JaziarAuthor 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?
0
 
JaziarAuthor Commented:
import matrix.util.Version; Allways errors here - says class not found on import
0
 
Sjef BosmanGroupware ConsultantCommented:
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.
0
 
JaziarAuthor 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.
0
 
JaziarAuthor 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();
            }
      }
}
0
 
Sjef BosmanGroupware ConsultantCommented:
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;
    }

}
0
 
JaziarAuthor Commented:
EBOMQuery ebomQuery = new EBOMQuery(); errors -> class not found
0
 
Sjef BosmanGroupware ConsultantCommented:
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?

0
 
JaziarAuthor 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?
0
 
Sjef BosmanGroupware ConsultantCommented:
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.
0
 
JaziarAuthor 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.
0
 
Sjef BosmanGroupware ConsultantCommented:
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.
0
 
JaziarAuthor 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?
0
 
Sjef BosmanGroupware ConsultantCommented:
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...
0
 
Sjef BosmanGroupware ConsultantCommented:
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
0
 
JaziarAuthor Commented:
I think this problem has been answered, I am now working on the Java code
0
 
Sjef BosmanGroupware ConsultantCommented:
Well done! And thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 15
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now