在运行时检查 --module-path 值

Art*_*rov 4 java java-9 java-module module-path

有什么方法可以在运行时使用-p--module-path参数获取模块路径中包含的目录列表,类似于我使用 获取所有类路径目录的方式System.getProperty("java.class.path")

Zhe*_*lov 5

来自 Javadoc 的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
Run Code Online (Sandbox Code Playgroud)

所以你应该使用 System.getProperty("jdk.module.path")

  • 更好的方法是 [如艾伦的建议](/sf/ask/3538078771/#comment88100258_50543982) (2认同)