吵吵   2011-10-25  阅读:3,377

为什么要用LotusScript调用Java库我就不再说了,用到的朋友会明白,我这里仅仅描述一下调用的过程。1、首先创建一个Java库(一个简单的测试)


在库中创建一个Java class,代码如下
public class SayHello {
private String username;

public SayHello(){

}
public SayHello(String username){
this.setUsername(username);
}

public void hello(){
if(“”.equals(this.username)||null==this.username){
System.out.println(“someOne Says Hello World!”);
}else{
System.out.println(this.username+” Says Hello World!”);
}
}

public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}

}
2、创建ls代理

%REM
Agent agentTestCallJava
Created 2011-3-29 by Administrator/OA_CEAJS
Description: 用来测试在LotusScript代理中调用Java库
%END REM
Option Public
Option Declare
UseLSX “*javacon” ‘必须的
Use “sayHello” ‘调用我们的库
Dim session As NotesSession
Dim userName As NotesName
Dim jSession As javasession
Dim sayHelloClass As javaclass
Dim helloObject As javaobject
Sub Initialize()
Call createJavaObjectNoArgument
Call createJavaObjectWithArguments
End Sub
%REM
Function createJavaObjectNoArgument
Description: Comments for Function
%END REM
Function createJavaObjectNoArgument()
On Error GoTo errorp
‘创建java对象
Set jSession=New javaSession()
Set sayHelloClass=jSession.GetClass(“SayHello”)
Set helloObject=sayHelloClass.Createobject()
Call helloObject.hello()
Exit Function
errorp:
MsgBox “Error ” + Error$ + ” at line” + Str(Erl()) + ” of agentTestCallJava”
Exit Function
End Function
%REM
Function createJavaObjectWithArguments
Description: Comments for Function
%END REM
Function createJavaObjectWithArguments()
On Error GoTo errorp
Set session = New NotesSession()
Set userName=session.Createname(session.EffectiveUserName)
‘创建java对象
Set jSession=New javaSession()
Set sayHelloClass=jSession.GetClass(“SayHello”)
Set helloObject=sayHelloClass.Createobject(“(Ljava/lang/String;)V”,userName.Common)
Call helloObject.hello()
Exit function
errorp:
MsgBox “Error ” + Error$ + ” at line” + Str(Erl()) + ” of agentTestCallJava”
Exit function
End Function

说明:1、调用Java库必须使用 UseLSX “*javacon”

2、CrateObject调用的是构造方法,如果参数是完整类路径前面加(L),后面要加分号(;)

吵吵微信朋友圈,请付款实名加入:

吵吵 吵吵

2条回应:“在LotusScript代理中调用Java库”

  1. 美女博客说道:

    博主,联盟上新广告了!你对联盟和我个人有什么想法,请多多指正,多提宝贵意见!

  2. 贺昌说道:

    独立博客圈的达人好多哇~

发表评论

电子邮件地址不会被公开。 必填项已用*标注