从 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 程序)。看起来我可以让代码运行,但是,我不能让它在任何断点处停止。我收到的消息是:
Unable to install breakpoint in dk.domain.AgentTemplate due to missing line number attributes. Modify the compiler options to generate line number attributes.
我尝试将调试配置设置为“在主程序中停止”。它似乎确实停止了。但是,如果我跨过,它会运行所有代码 - 并且我看不到我在代码中的位置,当然我看不到变量及其值。
已选择“首选项 - Java - 编译器”中的“向生成的类文件添加行号属性”选项。我还没有找到其他编译器选项来生成行号。
我在 Designer 中使用 Java 1.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
}
我在代码中留下了“打印”命令,以便于测试。显然,您会从真正的模板中删除它们。
可能有助于使其正常工作的另一件事是我更改了配置参数的大小写,以与磁盘上的目录完全相同的大/小写字母匹配。
/约翰
关于java - 如何调试Java代理(二头兽方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12950109/