How To
ForgeRock Identity Platform
Does not apply to Identity Cloud

How do I invoke a jar file from a Groovy script in IDM (All versions)?

Last updated Jan 12, 2023

The purpose of this article is to provide information on class loading from a Groovy script in IDM.


The GroovyScriptLoader is used to load classes within a Groovy script. You can use the information in this article to specify the classpath for classes loaded directly as well as those loaded indirectly.

If you experience issues with classes not being found, for example, you see errors such as NoClassDefFoundError or ClassNotFoundException:

SEVERE: Script invocation error java.lang.NoClassDefFoundError: full/class/name ... Caused by: java.lang.ClassNotFoundException: at$ at groovy.lang.GroovyClassLoader.loadClass(

You can resolve it by specifying the classpath for the implementing jar files.

Finding classes

You can find classes in an IDM installation as follows:

  1. Run the following command from the root directory of the installation: for x in */*.jar; do echo ">>> $x"; jar tvf $x; echo "<<< $x"; echo; done > jars.logThe resulting file will list all classes found in any jar files.
  2. Search the list of classes for the one referenced in the error.
  3. Scroll up or down from the class to locate the jar file that contains it.
  4. Invoke the required jar file per the steps in this article.

Invoking a jar file from a Groovy script

You can invoke a jar file from a Groovy script as follows:

  1. Add the external jar file to the /path/to/idm/lib directory.
  2. Update the script.json file (located in the /path/to/idm/conf directory) to append the complete path to the jar file in the groovy.classpath, per your operating system:
    • Unix® and Linux® systems: "groovy.classpath" : "&{idm.install.dir}/lib:&{idm.install.dir}/lib/custom-lib-test-1.0.0.jar",
    • Microsoft® Windows® systems: (The groovy.classpath requires a semicolon ';' separator on Windows instead of a ':') "groovy.classpath" : "&{idm.install.dir}/lib;&{idm.install.dir}/lib/custom-lib-test-1.0.0.jar",
  3. Update the Groovy script to import the class(es) and invoke them, for example: import org.sample.Sample samp = new Sample(); java.lang.System.out.println('It is working: ' + samp.reverse("testing"));

You can add multiple jars to the classpath as detailed in Script Configuration.


If the jar file is not loaded, you should try the following process to remove any outdated generated classes:

  1. Shutdown the IDM instance.
  2. Delete the install-dir/classes directory.
  3. Delete the contents of the /path/to/idm/felix-cache directory.
  4. Start the IDM server.

See Also

How do I call one Groovy script from another in IDM (All versions)?

How do I add logging to Groovy scripts in IDM (All versions)?

Scripts in IDM


Related Training


Related Issue Tracker IDs


Copyright and Trademarks Copyright © 2023 ForgeRock, all rights reserved.