As the title says, I'm looking for a simple example in github that contains a code example that shows how to use the [the maven-shade-plugin] to rename classes when two versions of a library must be included in an application.
In the mean time, I'm starting to create my on version of this example and will post what I've created if no one points one out to me.
I have found several web pages that describe the plugin but nothing that has included a pointer to a repo with sample code.
Some useful writes up on the maven-shade-plugin
-
Each of the pom files create a JAR file so there are 4 (four) jar files created by this code example.
Summary of the Problem
The next diagram shows the loglib.jar file being used in both the main application (helloworld)
It shows the class
LogIt
contains a methodsayHello
which takes one argument String name in version 1.0.0 of the package (liblog.jar) andsayHello
takes two arguments in the 2nd version of the package.While this example is contrived to demonstrate the general problem that faces Java developers on more complex code bases, this simplified version of the problem is intended to make the problem easy to understand and to fix.
So by default, when a FAT jar is created for the HelloWorld application, the Fat jar only contains one copy of the class file
com.steranka.play.LogIt
. The result is that either theHelloWorld
class will crash or theGoodFeature
class will crash. Where crash means throw an exception Below is an example of the exception I saw when I first ran the application.Hello World! What's up, Sam Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String com.steranka.play.LogIt.sayHello(java.lang.String)' at com.steranka.play.GoodFeature.sayGoodbye(GoodFeature.java:6) at com.steranka.play.HelloWorldApp.main(HelloWorldApp.java:15)
This problem occurs because version 2.0.0 of the loglib.jar was used which contained the signature:
sayHello(String name, String greeting)
and the code in
GoodFeature.sayGoodbye
had bytecode which called the version 1.0.0 of the signature which was:sayHello(String name)
Since that signature did not exist, the exception occured.
The Solution
The solution is to include both versions of the
loglib
jar file as shown in the next diagram.Next Steps
If you want to follow along with what I did, and learn how I solved this problem continue here with the doc/01-Starting.md file.