如何调试Java代理(双头兽方法)

时间:2012-10-18 08:20:12

标签: java debugging lotus-notes lotus agent

自Notes / Domino第7版以来,我使用了Bob Balaban的“双头野兽”中的原则(http://bobzblog.com/tuxedoguy.nsf/dx/the-2-headed-beast-debugging-domino-java -agents-with-eclipse)用于在Eclipse中编写可以调试的Java代理!这就像一个魅力 - 唯一的问题是我必须将代码从Eclipse复制/粘贴到标准Notes代理。

使用Domino Designer的当前Eclipse版本(8.5.3 FP2),我试图查看是否可以使用相同的设置在Domino Designer中直接调试代理(作为Java程序)。似乎我可以让代码运行,但是,我不能让它停在任何断点。我得到的信息是:

  

由于缺少行号属性,无法在dk.domain.AgentTemplate中安装断点。修改编译器选项以生成行号属性。

我尝试将调试配置设置为“Stop in main”。它确实似乎停止了。但是,如果我跳过它,它会运行所有代码 - 我无法看到代码中的哪个位置,当然我看不到变量及其值。

已选择“首选项 - Java - 编译器”中的“将行号属性添加到生成的类文件”中的选项。我还没有找到其他编译器选项来生成行号。

我在Designer中使用Java 1.5合规性。

有没有人能够设置它?

/约翰

1 个答案:

答案 0 :(得分:5)

好吧,有时你只需要解释你的问题就可以找到解决方案。

在彻底描述问题时,我最终尝试使用JDK 1.6编译器合规级别(在首选项 - Java编译器下)。这实际上有效!!!

因此,构建具有此类结构的代理程序,您可以直接在Domino Designer中调试Java代理程序:

package dk.dalsgaarddata;

import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.DocumentCollection;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.Session;
import dk.dalsgaarddata.debug.DebugAgentContext;

/*  ------------------------------------------------------------------------------------
    Created: 2009.04.21/Jda
    Revised: 2009.04.29/Jda - v.1.1

    Agent template.... 
    ------------------------------------------------------------------------------------ */

public class AgentTemplate extends AgentBase {
    // DEBUG: For Eclipse debugging - see main method at the end of this class.

    // Beginning of "ordinary" Lotus Notes/Domino Agent....
    private Session mySession = null;
    private AgentContext myContext = null;
    private DD_BackendLog myLog = null;

    private void cleanUp() {
        try {
            if (null != myLog)
                myLog.end();
            if (null != mySession)
                mySession.recycle();
        } catch (NotesException ne) {
            System.err.println("Error cleaning up log and Session.");
        }
    }

    // Lotus Notes/Domino entry point...
    public void NotesMain() {
        try {
            if (mySession == null) {
                mySession = getSession();
                myContext = mySession.getAgentContext();
            }
            SessionContext.getInstance(mySession, myContext);
            myLog = SessionContext.getLog();

            System.out.println("NotesMain Started....");
            // Your code goes here....

            myLog.information(".... completed!");
        } catch (NotesException ne) {
            myLog.error("Agent ERROR: NotesException = " + ne.text);
            myLog.writeStackTrace(ne);
        } catch (Exception e) {
            myLog.error("Agent ERROR: Exception = " + e.getMessage());
            myLog.writeStackTrace(e);
        } finally {
            cleanUp();
        }
    }

    /*  Instructions for debugging!!
    // TODO - adjust run configuration
        You need to add VM arguments, e.g.:

            -Dsun.boot.library.path="c:\\Lotus\\Notes;c:\\Lotus\\Notes\\jvm\\bin"

     ... and you need to add a PATH environment variable, e.g.:

            PATH    c:\Lotus\Notes
    */

    // Remember to rename these constructors when duplicating this code to a new agent!!!
    // ... if not handled by Eclipse when pasting a copy ;-)
    public AgentTemplate() {
    }

    public AgentTemplate(Session s, AgentContext c) {
        this.mySession = s;
        this.myContext = c;
    }

    // Entry point for Java program (when running from Eclipse)
    public static void main(String[] args) {
        // By example from Bob Balaban "The two-headed beast". See more at:
        // http://www.bobzblog.com/tuxedoguy.nsf/dx/DominoAgents-Eclipse_v2.pdf/$file/DominoAgents-Eclipse_v2.pdf
        System.out.println("main Starting....");
        Session s = null;
        Database d = null;
        DocumentCollection dc = null;
        AgentContext ctx = null;

        System.out.println("NotesThread.sinitThread()....");
        NotesThread.sinitThread();
        try {
            System.out.println("createSession....");
            s = NotesFactory.createSession();
            System.out.println("set database....");
            d = s.getDatabase(DebugAgentContext.ECLIPSE_SERVER, DebugAgentContext.ECLIPSE_DATABASE);
            System.out.println("Database: " + d.getFileName() + " on " + d.getServer());
            System.out.println("set debug context....");
            ctx = new DebugAgentContext(s, d, dc);
            // Create the agent object, invoke it on NotesMain(), the way Domino does
            System.out.println("create agent object....");
            AgentTemplate agent = new AgentTemplate(s, ctx);
            System.out.println("call agent....");
            agent.NotesMain();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (s != null)
                    s.recycle();
            } catch (Exception x) {
            }
            NotesThread.stermThread();
        }
    } // end main - and Eclipse entry point

}

我在代码中留下了“print”命令,以便于测试。显然,你会从真实的模板中删除它们。

可能有助于实现此功能的另一件事是我更改了配置参数的大小写,以匹配与磁盘上的目录完全相同的大小写。

/约翰