JavaFileManager.getModuleLocation() problem

Jonathan Gibbons jonathan.gibbons at oracle.com
Wed Jul 27 17:20:52 UTC 2016


If your module is in source form, then you have two choices:

1. put the contents of the module directly on the SOURCE_PATH, as a 
hierarchy of packages and types, with module-info.java in the root of 
that hierarchy. by contrast with using MODULE_SOURCE_PATH, (described 
next), there should not be any enclosing directory.  In your program, 
access the module contents using StandardLocation.SOURCE_PATH, (no need 
for getModuleLocation).   In this case SOURCE_PATH *is* the module location.

2. put the contents of one or more modules on the MODULE_SOURCE_PATH.  
The contents of each module should be in directory named for the module. 
Each directory should contain a hierarchy of packages and types, with 
module-info.java in the root of that hierarchy. The name of the module 
in the module-info.java file must match the name of the enclosing 
directory.  In your program, get a location for the contents of a 
specific module on the module source path using
standardFileManager.getModuleLocation(StandardLocation.MODULE_SOURCE_PATH, 
moduleName)

If your module can been compiled, you should normally put the module on 
the module path and access it via MODULE_PATH.    The module can be 
represented as a "exploded directory" of packages and types, or as a 
modular jar file (i.e. containing module-info.class) or as an automatic 
module (a jar file that does not contain module-info.class).   Whatever 
the form of the module, you can either place it directly on the module 
path, or in a directory on the module path.  In your program, get a 
location for the contents of a specific module on the module path using
standardFileManager.getModuleLocation(StandardLocation.MODULE_PATH, 
moduleName)


Generally, if a path is described as a "module path" of some sort, use 
getModuleLocation(path, moduleName) to get the contents of a specific 
module. If a path is described as a "class path" or (simple) "source 
path" then it can only contain a single module, which may be the unnamed 
module, in which case, use the path directly (e.g. 
fileManager.list(path, ...) ) to get the contents of the module.

-- Jon

On 07/27/2016 07:42 AM, Konstantin Barzilovich wrote:
> Thanks for the answer.
> I managed to find system module with SYSTEM_MODULES.
> But I still don't understand how to find my own module.
> As I understand, I need to have path to compiled module in modulepath.
> I tried both MODULE_SOURCE_PATH and MODULE_PATH, but I failed.
> Could you please explain where module should be in order to be found.
>
>
> -- 
> Thanks,
> Konstantin.
>
>> SOURCE_PATH is normally a package-oriented (JDK-8 style) path.  It's 
>> not a module-oriented path, so generally, you won't find modules on it.
>>
>> You probably want to use MODULE_SOURCE_PATH.
>>
>> -- Jon
>>
>>
>>
>> On 07/26/2016 06:59 AM, Konstantin Barzilovich wrote:
>>> Hello,
>>>
>>> I try to use method getModuleLocation() like this:
>>>
>>> JavaFileManager.Location location = 
>>> ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, 
>>> null, null).getModuleLocation(StandardLocation.SOURCE_PATH, 
>>> "myModule");
>>>
>>> But variable 'location' is always null.
>>> I expected UnsupportedOperationException or some result, but not null.
>>> What am I doing wrong?
>>>



More information about the jigsaw-dev mailing list