How to get a resource from a java agent in Lotus

In this post I explain how to get a resource, for example an image, from a java agent even if this file is not saved on the file system.
The agent is tested in lotus client 8.5.x.

    1. Create a java agent


    1. Import an image as a resource by using the button Import -> Resource


    1. Edit the class JavaAgent:
      import lotus.domino.*;
      import java.awt.image.BufferedImage;
      import javax.imageio.ImageIO;
      public class JavaAgent extends AgentBase {
      	public void NotesMain() {
      		try {
      			Session session = getSession();
      			AgentContext agentContext = session.getAgentContext();
      			// (Your code goes here)
      			// first example: from image resource to bytes
      			// you need
      			InputStream is = getClass().getClassLoader().getResourceAsStream("myPicture.jpg");
      			byte[] bytes = IOUtils.toByteArray(is);
      			// second example: from image resource to file
      			InputStream in = (ByteArrayInputStream)getClass().getClassLoader().getResourceAsStream("myPicture.jpg");
      			BufferedImage img =;   
      			ImageIO.write(img, "jpg", new File("c:\\myPicture.jpg"));
      		} catch(Exception e) {


In the first example the image is converted to bytes (you need to import and to import the relative .jar file under Archive)
In the second example the image is saved on the disk.


2 responses to “How to get a resource from a java agent in Lotus”

  1. Can you load an image added as an image resource inside the nsf directly?

    1. Luca Zanini Avatar
      Luca Zanini

      This code doesn’t work with image resource inside the nsf directly.
      Maybe you can see this example.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.