Adding module descriptor to existing JAR file

Alan Bateman Alan.Bateman at
Mon Feb 6 09:26:44 UTC 2017

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.


More information about the jigsaw-dev mailing list