我最终会在我的笔记文档中写入一些自定义数据。但在此之前,我想看看它是如何工作的,所以我从 IBM 知识中心复制/粘贴了关于在两个单独的代理中替换/getItemValueCustomData 的示例。
问题是当我尝试读取自定义数据时,读取代理抛出异常:
java.lang.ClassNotFoundException: customData.IntIntString
at java.lang.Class.forName(Class.java:291)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:619)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1609)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1768)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:364)
at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:14)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
代码如下:
写代理:
import customData.IntIntString;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
IntIntString iis = new IntIntString();
iis.setData(1, 2, "String1");
Document doc = agentContext.getDocumentContext();
doc.replaceItemValueCustomData("IntIntStringItem", "IntIntStringType", iis);
doc.save();
} catch (Exception e) {
e.printStackTrace();
}
}
读取代理:
import intIntString.IntIntString;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document doc = agentContext.getDocumentContext();
if (doc.hasItem("IntIntStringItem")) {
IntIntString iis = (IntIntString) doc.getItemValueCustomData("IntIntStringItem", "IntIntStringType");
iis.show();
} else {
System.out.println("No item IntIntStringItem in document");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
IntIntString 类:
package customData;
import java.io.Serializable;
public class IntIntString implements Serializable {
private static final long serialVersionUID = 6875473472063311349L;
private int int1;
private int int2;
private String string1;
public void setData(int i1, int i2, String s1) {
int1 = i1;
int2 = i2;
string1 = s1;
}
public void show() {
System.out.println("Int1 = " + int1);
System.out.println("Int2 = " + int2);
System.out.println("String1 = " + string1);
}
}
代理写入的字节数:
. I n t I n t S t r i n g T y p e . . .
10 49 6E 74 49 6E 74 53 74 72 69 6E 67 54 79 70 65 AC ED 00
. s r . . c u s t o m D a t a . I n t I
05 73 72 00 17 63 75 73 74 6F 6D 44 61 74 61 2E 49 6E 74 49
n t S t r i n g _ j . . . . . . . . . I
6E 74 53 74 72 69 6E 67 5F 6A 96 B1 EC F4 8D F5 02 00 03 49
. . i n t 1 I . . i n t 2 L . . s t r i
00 04 69 6E 74 31 49 00 04 69 6E 74 32 4C 00 07 73 74 72 69
n g 1 t . . L j a v a / l a n g / S t r
6E 67 31 74 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72
i n g ; x p . . . . . . . . t . . S t r
69 6E 67 3B 78 70 00 00 00 01 00 00 00 02 74 00 07 53 74 72
i n g 1
69 6E 67 31
是我错过了什么还是 IBM 喝醉了?
示例链接:replaceItemValueCustomData method , getItemValueCustomData method .
编辑:尝试在“Agent”类中定义“IntIntString”类,但这没有用,也没有将该类放入 .jar 中并导入它。
编辑 2:正如评论中所建议的,我试图在代理中将类声明为 public。出于某种原因,当我尝试必须在代理中实现 Serializable 时,我做到了。仍然有同样的异常(exception)。
然后我尝试在“customData”包中的单独文件中将其声明为公共(public)(因为公共(public)类需要它们自己的文件),但这也不起作用。
还尝试在文档以读取模式打开时读取该字段。我得到了那个异常并且该字段被删除了(从文档属性中看到):
NotesException: Supplied Data type name does not match stored CustomData type
at lotus.domino.local.Document.NgetItemValueCustomData(Native Method)
at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:14)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
字段未正确读/写的接缝,数据类型应匹配。
代码已更新。
最佳答案
从自定义类 IntIntString 创建一个 jar 文件
import java.io.Serializable;
// Define custom data
public class IntIntString implements Serializable {
private static final long serialVersionUID = 1L;
int int1;
int int2;
String string1;
public void setData(int i1, int i2, String s1) {
int1 = i1;
int2 = i2;
string1 = s1;
}
public void show() {
System.out.println("Int1 = " + int1);
System.out.println("Int2 = " + int2);
System.out.println("String1 = " + string1);
}
}
将jar文件放入文件夹
- domino/jvm/lib/ext(Domino 服务器 - 用于后端和 runOnServer 代理)
- notes/jvm/lib/ext(Notes 客户端 - 用于在客户端启动的代理)
这样,ObjectInputStream 可以找到自定义类 IntIntString,因为它在代理的 JVM 中全局可用。这是 IBM 的 replaceItemValueCustomData/getItemValueCustomData 文档中缺失的部分。
关于java - 运行 IBM 代码示例时出现 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38645424/