My project has the following situation:
a large module (the converter calling it) is integrated into the main application with its own dependencies (which was developed separately by different people and has its own partially overlapping dependencies);
initially this converter module was called from the command line as an executable flag, so it has its own entry points (runnable classes with specific main () methods); this executable jar has always been created as uber-jar through the maven shade plugin;
Now this converter module should be additionally called from the main application (for this I, at the moment, immediately call main () of the entry point classes after generating the command line arguments). The main application is also created as uber-jar and is planned to continue in this way.
So, I am going to achieve the correct separation of dependencies using the shadow plugin for this case. To do this, I added the following reinstallation options to pom.xml for the converter module:
<relocations> <relocation> <pattern>com</pattern> <shadedPattern>quase.com</shadedPattern> </relocation> <relocation> <pattern>org</pattern> <shadedPattern>quase.org</shadedPattern> <excludes> <exclude>org.aau.**</exclude> </excludes> </relocation> </relocations>
As a result, all the dependencies of the converter module are shaded (with preliminary quasi to them), and then combined into the uber-jar of the main application.
The problem with this configuration is that both the application and the converter use logging (slf4j with log4j), and after the converter method is called from the application code and starts using logging, the following error occurs:
log4j:ERROR A "org.apache.log4j.FileAppender" object is not assignable to a "quase.org.apache.log4j.Appender" variable. log4j:ERROR The class "quase.org.apache.log4j.Appender" was loaded by log4j:ERROR [ sun.misc.Launcher$AppClassLoader@55f96302 ] whereas object of type log4j:ERROR "org.apache.log4j.FileAppender" was loaded by [ sun.misc.Launcher$AppClassLoader@55f96302 ]. log4j:ERROR Could not instantiate appender named "file1". log4j:ERROR A "org.apache.log4j.FileAppender" object is not assignable to a "quase.org.apache.log4j.Appender" variable. log4j:ERROR The class "quase.org.apache.log4j.Appender" was loaded by log4j:ERROR [ sun.misc.Launcher$AppClassLoader@55f96302 ] whereas object of type log4j:ERROR "org.apache.log4j.FileAppender" was loaded by [ sun.misc.Launcher$AppClassLoader@55f96302 ]. log4j:ERROR Could not instantiate appender named "file2". log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "quase.org.apache.log4j.Appender" variable. log4j:ERROR The class "quase.org.apache.log4j.Appender" was loaded by log4j:ERROR [ sun.misc.Launcher$AppClassLoader@55f96302 ] whereas object of type log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [ sun.misc.Launcher$AppClassLoader@55f96302 ]. log4j:ERROR Could not instantiate appender named "console". log4j:WARN No appenders could be found for logger (org.aau.quase.quontology.builder.QuLogHandler). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html
So, it seems to me that the shaded registration code, called from the converter module, gets a link to the undamped registration code already initialized in the main application, and fails because it expects a shaded code (see refusal to assign non-shaded org.apache.log4j.FileAppender in shading quase.org.apache.log4j.Appender ).
I tried to eliminate shading dependency dependencies in the pom.xml converter:
<excludes> <exclude>org.aau.**</exclude> <exclude>org.apache.log4j.**</exclude> <exclude>org.slf4j.**</exclude> </excludes>
but this led to further problems: the entire application does not work as follows:
Exception in thread "main" java.lang.NoClassDefFoundError at org.apache.log4j.Category.class$(Category.java:118) at org.apache.log4j.Category.<clinit>(Category.java:118) at org.apache.log4j.LogManager.<clinit>(LogManager.java:82) at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:66) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288) at org.aau.quase.application.LoggingProtocolHandler.<clinit>(LoggingProtocolHandler.java:16) at org.aau.quase.application.QuASEApplication$1.<init>(QuASEApplication.java:71) at org.aau.quase.application.QuASEApplication.<init>(QuASEApplication.java:65) at org.aau.quase.application.util.QuASERunner.main(QuASERunner.java:8) Caused by: java.lang.ClassNotFoundException: quase/org.apache.log4j.Category at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) ... 10 more
It seems that the converter code is still waiting for the shaded version, as it cannot find quase/org.apache.log4j.Category , and quase is the hatch prefix.
What am I doing wrong? Any help is appreciated.