javajarxpageslotus-notes

How to add external third party jar in Notes Xpages application?


I am Java developer, recently working on Xpages project. we are using Notes 9.0.1. I created Java agent to send email and I want to use some third party jar, something like org.apache.commons.lang3 , end up this issue. how to add third party jar, like commons-lang3-3.4.jar, in my Xpages project?

I tried different ways

  1. add jar under /jvm/lib/ext folder, restart DDE.the I can see it in my project JRE system libray, but could not import in my Java code. Maybe this is the way for server deployment.
  2. add jar under /Code/Jars and then DDE generated with new name added in /Webcontent/WEB-INF/lib, but...
  3. Add jar directly under /Webcontent/WEB-INF/lib, but not appeared /Code/Jars in Application view
  4. add jar under the Java agent Archive folder, but...

None of them allows me import the package in my Java code.

Anything I did wrong, or is there any good way to add third party jar in XPages project.

Thanks


Solution

  • If you add a JAR to your project by importing it into /Code/JARs, it should be added so as to be accessible by your build path(2,3). The same is true of your /WebContent/WEB-INF/lib, but that may not be automatically defined in your version of DDE; for example, Domino Designer 9 has the design elements of /Code/Java and /Code/JARs, which didn't previously exist (these are separate folders/paths from /WebContent/WEB-INF/src or /WebContent/WEB-INF/lib, either can be in the build path). In either case, if your approach is to have the JAR in your NSF, make sure your build path has the path with your JARs. Separately you could add each JAR individually.

    You can get to the Build Path via Project > Properties, then for the part of your build path concerning JARs, go to "libraries":

    individual JARs in Project Build Path individual JARs in Project Build Path

    JAR class path in Build Path (ex- /WebContent/WEB-INF/lib) JAR class path

    As for the path of using the /jvm/lib/ext folder approach, I've covered that in a blog post and it's important to remember to have the JARs in the appropriate relative path both on the server and in your Designer/local path (otherwise your local, DDE, may not pick up the change).(1)

    For both, if you keep build automatically turned off, you'll want to make sure you perform another build to see the changes.

    As for a Java Agent archive, this should just work and again I'm wondering whether your build automatically setting is enabled/disabled. The /jvm/ext/lib path ought to work for this as well (shown in my linked blog post).(4)

    *Note: as Paul Withers points out in the comments, importing a JAR to a Java Agent can introduce memory leak issues, making the /jvm/ext/lib/ path preferable.

    *Further note: per Thomas Adrian's comment below, the issue with memory leaks with JARs may be addressed circa v12 and later.

    Java Agent archive inclusion