从 SSJS xPages 调用一个 jar 类 [英] Call a class of a jar from SSJS xPages

查看:33
本文介绍了从 SSJS xPages 调用一个 jar 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个关于在 xPages 上使用 SSJS(服务器端 JavaScript)中的 Java 类的问题.我创建了一个简单的 Java 类HelloWorld"并将其导出到一个 jar 文件.然后我尝试在 xPage 上从 SSJS 调用它,但没有成功.这些是我尝试过的一些事情:

I would like to ask a question about using Java classes in SSJS (Server Side JavaScript) on xPages. I created a simple Java class "HelloWorld" and exported it to a jar file. Then I tried to call it from SSJS on an xPage but with no success. These are some things that I tried:

  1. 将 jar 添加到 .nsf 的构建路径中(jar 和 nsf 都是本地的)
  2. 将 jar 添加到 nsf 的 WEB_INF/lib 文件夹中.
  3. 直接从SSJS调用jar的类为

  1. Added the jar to the build path of the .nsf (both jar and nsf were local)
  2. Added the jar to WEB_INF/lib folder of the nsf.
  3. Called the class of the jar directly from SSJS as

var a = new com.myself.testJava.HelloWorld();

var a = new com.myself.testJava.HelloWorld();

从我在 nsf 中创建的另一个 Java 类调用该类,然后从 SSJS 调用第二个类.

Called the class from another Java class that I created in the nsf and then call the second class from SSJS.

我总是收到错误 500HTTP Web 服务器:命令未处理异常"

I always get an error 500 "HTTP Web Server: Command Not Handled Exception"

我还尝试在服务器上运行我的 xpage 并将 jar 文件添加到 jvm/lib/ext 文件夹.在这种情况下,错误是找不到com",我理解这意味着找不到该类.

I have also tried to run my xpage on a server and add the jar file to the jvm/lib/ext folder. In this case the error was "com" not found, which I understand that it means that the class cannot be found.

我已经在 nsf 中创建了一个 java 类,然后从 SSJS 调用,但我希望能够使用 3rd 方类.

I have accomplished to create a java class in the nsf and then call from SSJS, but I want to be able to use 3rd party classes.

您能否提供有关正确步骤的任何信息?

Could you please give any information about what are the correct steps?

非常感谢!

推荐答案

在 SSJS 的顶部,您需要执行 ImportPackage.

At the top of your SSJS you will need to do an ImportPackage.

importPackage(com.myself.testJava)

请注意,您需要导入包而不是类.现在 SSJS 的其余部分应该可以工作了.

Note that you need to import the package and not the class. Now the rest of your SSJS should work.

这篇关于从 SSJS xPages 调用一个 jar 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆