2

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!

1
  • Adding a JAR to WEB-INF/lib works for me w/o any problems... Dec 4, 2012 at 11:45

3 Answers 3

4

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
  • Thank you Declan! I added importPackage and it worked! Thanks a lot
    – kmak
    Dec 6, 2012 at 7:31
1

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.

2
  • I tried with the jar of JavaMail API too, to be sure that it wasn't a problem of my jar. I should have added importPackage as @Declan Lynch pointed out.
    – kmak
    Dec 6, 2012 at 7:39
  • I'm pretty sure that importPackage is not obligatory. I'm using full qualified names all around my app they work like a charm.
    – W_K
    Dec 7, 2012 at 8:29
0

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.

2
  • Thank you for the reply, but it seems the problem was I had to add importPackage to SSJS code.
    – kmak
    Dec 6, 2012 at 8:40
  • Interesting. I don't use it usually. Imports are optional just like in Java. Dec 6, 2012 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.