Log4j and the classpath
668470Sep 3 2009 — edited Sep 11 2009I ran into [this problem|http://forums.oracle.com/forums/message.jspa?messageID=3404370#3404370] some time ago. I was just learning Maven at the time, and figured out how to solve my problem with the Maven build (provided scope instead of compile scope.) Now I'm trying to solve the problem as it presents in the JDev embedded OC4J container deployment:
Condition 1) Attunitiy connector (tuxedo java interface) RAR comes packaged with log4j libraries (Third party package not under my control.)
Condition 2) Web application that uses log4j and is deployed to container on which Attunity connector is also deployed (Embedded OC4J container inside JDev installation.)
Option 1) If I deploy the web application with log4j as a dependency, it fails because the web application's instance of log4j will not coexist with the log4j instance included with the connector:
500 Internal Server Error
oracle.classloader.util.AnnotatedLinkageError: duplicate class definition: org/apache/log4j/Logger
Invalid class: org.apache.log4j.Logger
Loader: current-workspace-app.root:0.0.0
Code-Source: /C:/Data/maven/repository/log4j/log4j/1.2.8/log4j-1.2.8.jar
Configuration: <library> in /C:/Data/Jdev/Jws/FleetBridge_PS_AUG_01/FleetBridge-oc4j-app.xml
Dependent class: ody.fleet.servlet.TestServlet
Loader: current-workspace-app.web.WebApp:0.0.0
Code-Source: /C:/Data/Jdev/Jws/FleetBridge_PS_AUG_01/WebApp/classes/
Configuration: <classpath> in C:\Data\Jdev\Jws\FleetBridge_PS_AUG_01\WebApp\public_html
The original class instance was defined in the shared-library jca-legacy-adapter:0.0.0, and current-workspace-app.web.WebApp:0.0.0 does import that loader. This may be a search-order problem.
Option 2) If I remove log4j from the web application as a dependency, it won't compile because of unresolved references to log4j classes.
I can check the box: Run Project Despite Compile Errors and it will run since the missing classes at compile time are resolved at runtime from the log4j packaged with the connector. But there has to be a better way than dealing with expected compile time errors.
I thought that a library with the option "Deployed by Default" checked meant: Include in the classpath for compilation, but do not include when deploying since it is already "Deployed by Default". But I could be wrong, because even with that checked, log4j gets included in the runtime classpath and conflicts with the log4j in the connector.
How can I configure a library to be included in the classpath for compilation, but not included in the classpath for deployment at runtime?
Thanks,
Steve