Inspect --module-path value at runtime
Asked Answered
F

1

7

Is there any way to get list of directories which are included in module-path with use of -p or --module-path arguments at runtime similar to how I whold get all classpath directories using System.getProperty("java.class.path")?

Fabricate answered 26/5, 2018 at 14:53 Comment(4)
Why do you need the modulepath? What use case do you have?Walther
@Walther Just for debug purposesFabricate
The system property is jdk.module.path, documented in System.getProperties(). For completeness, you may want to look at the value of jdk.module.upgrade.path, also documented in System.getProperties().Sakti
@AlanBateman But why I don't have such systems properties even when --module-path was actually used? I am using java.runtime.version=9+181Fabricate
W
11

From Javadoc of System.getProperties:

In addition to the standard system properties,
the system properties may include the following keys:

Key                      Description of Associated Value
jdk.module.path          The application module path
jdk.module.upgrade.path  The upgrade module path
jdk.module.main          The module name of the initial/main module
jdk.module.main.class    The main class name of the initial module

So you should use System.getProperty("jdk.module.path")

Walther answered 26/5, 2018 at 15:32 Comment(1)
A better way would be as suggested by AlanPaniagua

© 2022 - 2024 — McMap. All rights reserved.