7.Java开发
1.原理
Java 是以 JNI (Java Native Interface) 接口规范调用硕正服务的,Eclipse 的实例请参考下载 JavaTest项目。
package supcan;
public class Service {
static
{
System.loadLibrary("winface");
}
public native long OpenReportService(String para);
public native void CloseReportService(long h);
public native int GetActiveServices();
public native String func(long h, String funcname, String para);
}

受 JNI 规范制约,您不能修改包名 "supcan" 和类名 "Service" ,否则将无法运行.
2.实例
项目包中的另一个类:RunDemo 类就是使用了 Service 类的例子,该例子仅是简单的 Java Application 应用,您可以先在此测试,测试通过后再将其改造成J2EE的后端项目。
public class RunDemo {
public static void main(String [] arg)
{
RunDemo demo = new RunDemo();
demo.func1();
}
public String func1()
{
//创建参数=======================
//TempDir请自己指定一个
String Para = "TempDir=F:\\eclipse\\workspace\\JavaTest\\Temp;";
//相对路径的参考值
Para += "BaseDir=http://localhost:8080/supcan;";
//其它参数
Para += "LogSize=1000;LogLevel=2;";
//创建一个Service类的实例
Service srv = new Service();
//防止潮水攻击
if(srv.GetActiveServices( ) > 10) {
throw new RuntimeException("服务器忙! ");
}
//创建服务
long hSrv = srv.OpenReportService(Para);
if(hSrv==0){
throw new RuntimeException("报表服务创建失败!");
}
//指定中心数据源的URL,参数是一个相对URL,相对于服务创建参数中的BaseDir,当然您也可以用绝对URL
srv.func(hSrv, "SetSource", "reportdata/datacenter.xml");
//打开报表
srv.func(hSrv, "build", "report\\center2-1.xml");
//计算、填充数据
srv.func(hSrv, "calc", "");
//创建临时文件
String TempFilename = srv.func(hSrv, "CacheDirUtility", "isCreateTempFile=true;ext=htm;DeleteEarlierFile=15m;KeepMB=10");
if(TempFilename == "") {
srv.CloseReportService(hSrv);
throw new RuntimeException("文件创建失败!");
}
//报表转换成html
srv.func(hSrv, "callfunc", "105\r\n type=htm;filename=" + TempFilename);
//关闭服务
srv.CloseReportService(hSrv);
return TempFilename;
}
}
3.部署
在测试时,您可以将硕正服务专版包中的那些文件全部解压到JavaTest目录,就能运行:

提醒:环境变量 Path 修改后, tomcat 需要重启.
4.简单JSP测试
以 tomcat 作为Web服务器, 按如下步骤做:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="supcan.*,java.util.*"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>test</title>
</head>
<body>
<%
try{
RunDemo demo = new RunDemo();
String s = demo.func1();
out.println(s);
}
catch(Exception e) {
out.println(e.getMessage());
}
%>
</body>
</html>
在浏览器地址栏输入 http://localhost:8080/test.jsp, 你应该能在网页上看到动态转换成功的 htm 文件名.