[英]How to call a java shared script library from a Java agent in Xpages?
I have an agent that is set to run every day at 8:00 我有一个每天将在8:00运行的代理
I want to write a java code (in a shared library) and call that library from the agent with parameters. 我想编写一个Java代码(在共享库中),并使用参数从代理中调用该库。
For Example: 例如:
Agent code: 代理代码:
// ....
checkAndSendMail(email_1);
checkAndSendMail(email_2);
// ....
java library code: Java库代码:
public class Check{
public void checkAndSendMail(String email_param){
// ...
mail.send(email_param);
// ...
}
}
The JVM in XPages and Domino Java Agents is separate so you can't share java code between them. XPages和Domino Java Agent中的JVM是分开的,因此您不能在它们之间共享Java代码。 You can create java code if you go to script libraries section in the designer 如果转到设计器中的脚本库部分,则可以创建Java代码。
not the Java/Jar section that is for XPages. 而不是XPages的Java / Jar部分。 And create a new Java Library that can be included inside a Java agent. 并创建一个可以包含在Java代理中的新Java库。
You can do this, but this is only possible with a lot of "overhead". 您可以执行此操作,但这只有在有很多“开销”的情况下才有可能。 Assuming you want to load a Java class in an Agent you could do the following: 假设要在代理中加载Java类,可以执行以下操作:
As you can see, it is possible, but for a higher effort than just "doubling" the libraries in the DDE. 如您所见,这是可能的,但是要付出更多的努力,而不仅仅是“加倍” DDE中的库。
EDIT: 编辑:
Here is an example class loader for an agent. 这是代理的示例类加载器。 The Base64 encoded DXL is already added. 已添加Base64编码的DXL。 The agent instantiates the class ch.hasselba.demo.LoadedClass and calls the method printTime() : 代理实例化类ch.hasselba.demo.LoadedClass并调用方法printTime() :
package ch.hasselba.demo;
public class LoadedClass {
public void printTime(){
System.out.println("Time: " + System.currentTimeMillis() );
}
}
The code of the agent (uses lwpd.commons.jar ) 代理的代码(使用lwpd.commons.jar )
import lotus.domino.AgentBase;
import com.ibm.commons.util.io.base64.Base64;
import java.lang.reflect.Method;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
// trucated DXL string
String dataDXL = "YQAYAAAAAACqAgAAAQAAAAAAAAAAAAAAYAC8AgAAqgKqAgAAAAAAAAAAyv66vgAAADEALwcAAgEAFWNoL2hhc3NlbGJhL3hwYWdlcy9aWgcA";
// base64 decode the string
String b64 = Base64.decode(dataDXL);
byte[] b64Bytes = b64.getBytes();
byte[] classBytes = new byte[b64Bytes.length - 42];
// skip the first 42 bytes
System.arraycopy( b64Bytes, 42, classBytes, 0, b64Bytes.length - 42);
try {
// load the class
ByteClassLoader obj = new ByteClassLoader();
Class theClass = obj.findClass("ch.hasselba.demo.LoadedClass", classBytes);
// instantiate it
Object theInstance = theClass.newInstance();
// get the method printTime via Reflection & call it
Method theMethod = theInstance.getClass().getMethod("printTime", null);
theMethod.invoke( theInstance, null);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
// the class loader
public static class ByteClassLoader extends ClassLoader {
public Class findClass(String name, byte[] data) {
return defineClass(name, data, 0, data.length);
}
}
}
Mike, Fredrik is right - no sharing. 迈克(Mike),弗雷德里克(Fredrik)是对的-不要分享。 Unless... you package your shared code into a Jar and deploy that one to the jvm/lib/ext directory of your server and/or client. 除非...将共享代码打包到Jar中,然后将其部署到服务器和/或客户端的jvm / lib / ext目录中。 Your admin will not like that potentially. 您的管理员可能不会这样。 There was a patched version of the updatesite.ntf on OpenNTF that allowed to deploy plug-ins into the server OS. OpenNTF上有一个updatesite.ntf的修补程序版本,允许将插件部署到服务器操作系统中。 You could hack the script to deploy a jar into the ext directory. 您可以修改脚本以将jar部署到ext目录中。 But please only with admin's consent. 但请先征得管理员同意。
:-) stw :-) STW
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.