Adding module descriptor to existing JAR file

Gunnar Morling gunnar at
Mon Feb 6 09:54:22 UTC 2017

Hi Alan,

Thanks for the quick reply. That does the trick.


2017-02-06 10:26 GMT+01:00 Alan Bateman <Alan.Bateman at>:
> On 06/02/2017 08:41, Gunnar Morling wrote:
>> Hi,
>> I'm trying to convert an existing non-modular JAR into a modular JAR.
>> Using jdeps, I was able to generate a descriptor for
>> the module-to-be. And the help text of the "jar" command discusses how
>> to add a compiled module descriptor to an existing JAR:
>>      jar --update --file foo.jar --main-class
>> --module-version 1.0
>>       -C foo/ module-info.class
>> I'm struggling though with compiling the module descriptor. I tried
>> with --patch-module and also by providing the existing JAR via
>> --class-path (as it's not a module yet), but javac is complaining
>> about the exported packages from the not being found:
>> error: package is empty or does not exist:
>>           exports
>> Is there an example somewhere that shows how to use javac for
>> compiling a module descriptor, given the classes from a non-module
>> JAR? I'm looking for a way without re-compiling that entire JAR, as I
>> don't think that's practical or even possible in some cases.
> If the classes in the module are in the output directory then javac should
> be able to compile the For the foo.jar example then I
> would expect this should work:
> mkdir classes
> (cd classes; jar xf ../foo.jar)
> javac -p <modulepath> -d classes
> jar uf foo.jar -C classes module-info.class
> The recipe is similar to what one would do when compiling the classes for an
> older release and then compiling the with a separate javac
> command.
> -Alan

More information about the jigsaw-dev mailing list