Forum Stats

  • 3,827,149 Users
  • 2,260,746 Discussions


How to set module-path with JNI_CreateJavaVM?

Stephan Bircher
Stephan Bircher Member Posts: 2
edited Apr 16, 2018 2:34PM in Java Native Interface (JNI)

I could not find a way how to set the module path using JNI_CreateJavaVM in Java 9 (9.0.4). I was expecting something like -Djava.class.path which is used to set the class path.

The jdk.internal.module,ModuleBootstrap class uses the system property "jdk.module.path".

        // --module-path option specified to the launcher

        ModuleFinder appModulePath = createModulePathFinder("jdk.module.path");

    private static ModuleFinder createModulePathFinder(String prop) {

        String s = System.getProperty(prop);

        if (s == null) {

            return null;

        } else {

            String[] dirs = s.split(File.pathSeparator);

            Path[] paths = new Path[dirs.length];

            int i = 0;

            for (String dir: dirs) {

                paths[i++] = Paths.get(dir);


            return ModulePath.of(patcher, paths);



However using -Djdk.module.path as JNI_CreateJavaVM argument is ignored with the following warning:

Java HotSpot(TM) 64-Bit Server VM warning: Ignoring system property options whose names match the '-Djdk.module.*'. names that are reserved for internal use.

Does anybody has an idea how to pass the module-path using JNI_CreateJavaVM. Or is there an alternative to create a jvm in Java9 which I have missed?



  • Stephan Bircher
    Stephan Bircher Member Posts: 2
    edited Apr 16, 2018 2:34PM

    The solution is to use the vm argument --module-path=path1:path2:.... which sets the module path properly. However lookup a class with findClass() from a specific custom module does not work unless having set

    -Djdk.module.main=myModule . You may also set -Djava.home=javaHomePath to make sure the java home is at the correct location.

This discussion has been closed.