modulepath and classpath mixture

Sander Mak sander.mak at luminis.eu
Mon Mar 7 13:53:28 UTC 2016


> I don't think I understand the issue here. Using -Xpatch doesn't change the module declaration or export. It can be used to override or augment the module content, it just can't override the module declaration. It can be used in conjunction with -XaddReads and -XaddExports to read additional modules or export additional packages. For example, if a patch adds types to a new package then you could export that package with -XaddExports. If the patch injects tests into an existing package then those tests might have new dependences and requires compiling or running with -XaddReads:$MODULE=junit for example.

I was playing around with exactly this yesterday, and this is what I ended up with:

javac -Xmodule:javamodularity.easytext.algorithm.naivesyllablecounter \
      -XaddReads:javamodularity.easytext.algorithm.naivesyllablecounter=org.junit \
      -mp mods:lib-test \
      -d mods-test/javamodularity.easytext.algorithm.naivesyllablecounter $(find src-test -name '*.java')

java -Xpatch:mods-test \
     -XaddReads:javamodularity.easytext.algorithm.naivesyllablecounter=org.junit \
     -XaddExports:javamodularity.easytext.algorithm.naivesyllablecounter/javamodularity.easytext.algorithm.naivesyllablecounter=org.junit \
     -mp mods:lib-test \
     -addmods javamodularity.easytext.algorithm.naivesyllablecounter,hamcrestcore \
     -m org.junit/org.junit.runner.JUnitCore javamodularity.easytext.algorithm.naivesyllablecounter.NaiveSyllableCounterTest

Which patches my application module to contain a unit test, and then exposes my application module to junit at runtime (which is used as automatic module here). This works as expected.


-- Sander


More information about the jigsaw-dev mailing list