2
votes

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. 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();

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

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

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.

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?

Thanks a lot in advance!

3
Adding a JAR to WEB-INF/lib works for me w/o any problems...Sven Hasselbach

3 Answers

4
votes

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

importPackage(com.myself.testJava)

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

1
votes

It look like there is some error in Your class - maybe unresolved compilation problem?

Please check out what is logged in xpages logs files on server.

You should be able to find the exception (with full stack) in file error-log-0.xml in '\Data\domino\workspace\logs' folder.

0
votes

All those should work but may require some fine tuning.

Try your 2. and place the JAR in build path with Domino Designer: Java Build Path -> Libraries -> Add JARs.