0

Previously to java 9, if one library externallib.jar had a bug in a class e.g. org.package.externalpackage.A, and I was able to correct it, I included the fixed class into tomcat's WEB-INF/classes like this:

WEB-INF/classes/org/package/externalpackage/A.class

which overrides the externallib.jar's A class.

As of java 9, this is not permitted in modular projects, as same packages (here org.package.externalpackage) are not allowed in different modules (the jar's module and my module).

What is the correct way to achieve this in java version as of 9?

Naman
  • 27,789
  • 26
  • 218
  • 353
Edu
  • 160
  • 10
  • You can do this in your build lifecycle. Compile the class separately and replace the class file with the destination class file. You should do this before executing the application. Bit of hackish, but it will get your job done. – Aniket Sahrawat Apr 27 '21 at 11:30
  • are you looking to [`--patch-module`](https://openjdk.java.net/projects/jigsaw/quick-start#xoverride)? – Naman Apr 27 '21 at 11:35
  • Replacing the classes would be kind of hackish as you mention and very difficult to maintain. – Edu Apr 27 '21 at 13:02
  • --patch-module seems interesting, but I see in the link that the user would have to enter --patch-module every time I change a new library for some reason. And if the user forgets to do this, the library class would be used, not the patched one. Is there any way to do this similar as above, where the user gets the patched classes and this works automatically without him/her changing the deployment? So analogous as above approach, which is valid? – Edu Apr 27 '21 at 13:05
  • take a look at the similar question https://stackoverflow.com/questions/50827263/patch-or-override-an-implementation-of-a-core-java-10-class – AlexElin Mar 01 '23 at 20:30

0 Answers0