Actually showing the password prompt when developing Java for Notes

If you’re developing console applications in Java that access Notes resources and you’re testing them in Eclipse you have experienced the following. You run your application to test it from Eclipse. It accesses a Notes resource and you haven’t granted 3rd party applications access in the Security settings so it causes Notes to ask you for the password – only the Console view doesn’t accept input… Bummer! 😦

Fortunately there’s a solution to this which I’ll show below.

Disclaimer: I can in no way take credit for this tip as I didn’t discover it. The credit goes to Karsten Lehmann who posted it in the Design Partner forum.

The solution is not to make the password prompt go to the Console view but pop up a password entry dialog instead. The way to do this is to initialize the Swing UI framework before running your application as I do below (see code in bold).

import javax.swing.SwingUtilities;
import lotus.domino.Session;
import lotus.domino.Database;
import lotus.domino.DocumentCollection;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;

public class Main {

  public static void main(String[] args) {
    try {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {}

      s s = NotesFactory.creates();
      System.out.println("Name: " + s.getUserName());
      Database db = s.getDatabase("server1/Example", "names.nsf");
      DocumentCollection dc = db.getAllDocuments();
      System.out.println("Docs: " + dc.getCount());

    } catch (Throwable t) {
    } finally {