title: How to create and run an agent from Java, using Lotus Notes API
body: <p>I am trying to create an agent and run it. I have created two classes, one extends <code>AgentBase</code> and the other one is a normal main class.
  I have written the code for agent in the 1st class and trying to run it from the second class. But I am not able to access it.
  I am a complete novice here, any guidance would be appreciated.</p>
  
  <p><code>Agent</code> Class:</p>
  
  <pre><code>import lotus.domino.*;
  
  import java.util.Vector;
  import sun.management.Agent;
  
  public class anagent extends AgentBase {
  
    public void NotesMain() {
  
      try {
        Session session = getSession();
        AgentContext agentContext = 
            session.getAgentContext();
  
        // (Your code goes here) 
  
        System.out.println("I am an agent");
      } catch(Exception e) {
        e.printStackTrace();
      }
    }
  </code></pre>
  
  <p><code>Main</code> Class:</p>
  
  <pre><code> public static void main(String [] args) throws NotesException {
  Session session = null;
  Database db = null;
          try {
          session =  NotesFactory.createSession(hostname,UserName, password);
      } catch (NotesException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      boolean x = session.isValid();
      System.out.println("success- "+x);
  
      try {
          db = session.getDatabase(null,"LotusDB2.nsf");
      } catch (NotesException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      if(db.isOpen())
      System.out.println("database open");
  
  
  
          //Agent agnt = (Agent) a.firstElement();
      //agnt.toString();}
       //AgentContext agentContext = session.getAgentContext();
        // db = agentContext.getCurrentDatabase();
         Vector agents = db.getAgents();
         //lotus.domino.Agent agent = new lotus.domino.Agent();
         System.out.println("Agents in database:");
         if(agents.size()&gt;0) System.out.println("some agents found");
         for (int i=0; i&lt;agents.size(); i++)
  
         {
  
           lotus.domino.Agent agent = (lotus.domino.Agent)agents.elementAt(i);
  </code></pre>