Search code examples
javaxpageslotus-notesxpages-ssjsdomino-designer-eclipse

Import a Java library and calling its classes through Lotus Script and SSJS


There is a library in the language of java, it needs to be called both with Lotus Script and SSJS. The script of the library runs without problems through Lotus Script, but there is no possibility of calling it on SSJS.

Java library:

public class Untitled { 

  public int add(int a, int b) { return a + b; }
  public int div(int a, int b) { return a / b; }
  public int mul(int a, int b) { return a * b; }
  public int sub(int a, int b) { return a - b; }
  public String dummy() {return "42"; }
}

enter image description here

Lotus Script

Option Declare
Uselsx "*javacon"
Use "one"

Dim myClass As JavaClass
Dim calculator As JavaObject
Dim mySession As JavaSession
Dim c As String
Set mySession = New JavaSession()
Set myClass = mySession.GetClass("com.two.Untitled")
Set calculator = myClass.CreateObject
c = calculator.dummy()
Messagebox c

Adding a library to the package does not work. I created the package and put the library there (Java code is similar)

SSJS

importPackage(com.myUntitled)
var myTest = new Untitled2();
return myTest.dummy();

enter image description here


Solution

  • If I understand it correctly, you have created a Java Script Library and try to call it from an XPage. Unfortunately that's not possible: to be able to use that Java code in an XPage/ SSJS you would have to copy it to a Java class (in the Code/Java section of an NSF).

    The only way I know of to share code and use it from LotusScript as well as XPages is by creating a JAR file and deploying that to the jvm/lib/ext folder.