Possibility to create modular jars out of old non-modular ones

Alex Buckley alex.buckley at oracle.com
Thu Sep 8 18:55:11 UTC 2016

On 9/8/2016 6:11 AM, Waldek Kozaczuk wrote:
> Imagine you have pre-jigsaw jar like log4j 1.x that happens to depend on
> java.awt.* and swing (it does in fact) but I know for a fact my app does
> not use this part of it.
> Would it be possible to create a modular jar out of non-modular by simply
> repackaging it and adding module-info.java that specifies what specifically
> my app depends on (is exposed in log4j jar)

Yes. By all means, add module-info.class to your app JAR.

The following thread from August will be helpful if you want to compile 
just module-info.java for JDK 9: 

> and what that log4j in my case "requires" from Java 9 in terms of
> modules?

The module-info.class file in your app JAR is the declaration of your 
application module. It can't contain dependencies for some other module. 
If you want your application module to say 'requires log4j', then your 
choices are to put log4j on the modulepath as an automatic module, or to 
find a version of log4j that is already a modular JAR.


More information about the jigsaw-dev mailing list