Have you ever wondered how you could call already written and quite useful Java classes in your LotusScript code? To me, this moment was, when I was trying to implement other department’s code into my own. Unfortunately I wasn’t skilled enough in ways of object development, LS2J  and googling back then to actually figure out that was possible. I remember thinking: “IBM implemented Java in Lotus Notes, they must have done some adaptor for it.”, but was unable to figure it out. Until couple of years back, when I got a Holy shit! moment, finding this blog post.

But why would I need that?

As you can see from the above examples, you can implement Java functionality to your LotusScript code. This can be good if your Java programming skills aren’t that great or you already have some code in LotusScript and you wish to add functionality. For me, it would do fine in cases where I converted documents in a database to PDF on user request, or when I needed an agent to login user to notes via web in the background, or as I mentioned, when I needed to implement some functionality from other department in my already existing code. Instead, I re-wrote several agents into Java, which in the end didn’t prove to be that bad of a decision, but about that some other day.

But how do I do that?

There is a functionality called LS2J that does exactly that for you. If you will, you can imagine it as an adaptor for LotusScript that allows you to call Java classes. I will give you a small example. It is based on my user login class, although, there is really no code there to log in the user.

First you need to create/obtain a java library that does what you want. I named that library jclass:UserLogin.

public class CUserLogin { 
   String m_strUsername; 
   String m_strPassword; 

   public void Initialize(String strUsername, String strPassword) { 
      if ((strUsername.length() == 0) || (strPassword.length() == 0)) return; 
      m_strUsername = strUsername; 
      m_strPassword = strPassword; 
   public boolean run() { 
      // add code that will perform auto-login return true; 

Then, I strongly suggest you create a LotusScript library, containing a class that will do actual Java to LotusScript conversion. Why? So you have to do it only once.
My script library called class:UserLogin is depicted below.

Uselsx "*javacon"
Use "jclass:UserLogin"

Class CUserLogin
 loginObj As JavaObject

 Sub New (strUsername As String, strPassword As String)
 Dim loginClass As JAVACLASS

 Set loginClass = js.GetClass ("CUserLogin")
 Set loginObj = loginClass.CreateObject ()

 Call loginObj.Initialize (strUsername, strPassword)
	End Sub

	Function run() As Boolean
 run = loginObj.run()
	End Function
End Class

And that is it. Now all you have to do, is use this script library in your code. Where you need it. I created a simple agent that will pop-up a window with text depicting login success.

Use "class:UserLogin"

Sub Initialize
 Dim userLogin As CUserLogin

 Set userLogin = New CUserLogin ("test", "test123")
	If (userLogin.run()) Then
 Messagebox "Login succeeded"
 Messagebox "Login failed!"
	End If
End Sub