Removing Jar from War - java

When I am deploying my war file in Jboss 5.1 , I am getting:
ERROR [STDERR] log4j:ERROR A "org.jboss.logging.appender.FileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
ERROR [STDERR] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
ERROR [STDERR] log4j:ERROR [BaseClassLoader#18c1f7d{vfszip:/C:/jboss-5.1.0.GA/server/default/deploy/OnlineUsage.war/}] whereas object of type
ERROR [STDERR] log4j:ERROR "org.jboss.logging.appender.FileAppender" was loaded by [org.jboss.bootstrap.NoAnnotationURLClassLoader#291aff].
ERROR [STDERR] log4j:ERROR Could not instantiate appender named "FILE".
Even with the above error , I can hit the ?wsdl URL correctly.
Next I tried simply by deleting the log4j jar file from war and deployed successfully without any error. Got ?wsdl correctly too.
My question is whether this will create problem in production or real time(Real time error or binding error).
In the past I got an error Failed to create SAX Parser. If it is not an issue to remove the jar from war, can I remove XercesImpl jar also? Since Jboss has its own jar files, I can avoid Class cast-exceptions.

In order to avoid class casting exception, I would highly recommend not packaging any JBoss or JDK provided jars in your WEB-INF/lib folder. If you have to for some reason, the utilize class loading isolation with jboss-classloading.xml file.
This principle holds true for other Java EE containers (Websphere, Weblogic, GlassFish, etc) as well. You never want to package JDK and container provided libraries in your own artifact.
You can make use JBoss Tattletale which is a great open source tool to find out what dependencies to not package in WAR/EAR.

Related

java.lang.ClassCastException - Log4j

When starting my managed server I see the following ClassCastException related to log4j in my WebLogic 12c managed server out file. I have commons-logging-1.1.1.jar and log4j-1.2.17.jar bundled in my WAR's lib directory and no other version of those libraries there. I also pasted the managed server log file error generated in in processing a request. Should I be using the log4j and commons logging that comes with WebLogic 12c? I see these in the modules directory: com.bea.core.apache.commons.logging_1.1.2.jar and com.bea.core.apache.log4j_1.2.0.0_1-2-15.jar. I haven't had a problem with log4j and WebLogic before.
out file:
jadomain.lang.ClassCastException: org.apache.log4j.RollingFileAppender cannot be cast to org.apache.log4j.Appender
at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.jadomain:248)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.jadomain:176)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.jadomain:191)
at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.jadomain:523)
at org.apache.log4j.xml.DOMConfigurator.parseCategory(DOMConfigurator.jadomain:436)
at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.jadomain:1004)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.jadomain:872)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.jadomain:778)
at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.jadomain:906)
at com.domain.d.app.restwrapper.ContextListener.contextInitialized(ContextListener.jadomain:37)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.jadomain:66
log file:
]] Root cause of ServletException.
jadomain.lang.LinkageError: loader constraint violation: when resolving method "org.apache.log4j.LogMF.entering(Lorg/apache/log4j/Logger;Ljadomain/lang/String;Ljadomain/lang/String;)V" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the current class, com/domain/d/app/restwrapper/appResource, and the class loader (instance of weblogic/utils/classloaders/GenericClassLoader) for resolved class, org/apache/log4j/LogMF, have different Class objects for the type /lang/String;)V used in the signature
at com.domain.d.app.restwrapper.appResource.addQuery(appResource.jadomain:244)
at com.domain.d.app.restwrapper.appResource.addQuery(appResource.jadomain:224)
at com.domain.d.app.restwrapper.appResource$Proxy$_$$_WeldClientProxy.addQuery(appResource$Proxy$_$$_WeldClientProxy.jadomain)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jadomain:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jadomain:43)
You have a conflict between tow versions of log4j. One is loaded from the server's classpath and the other one from your web application's classpath.
To resolve it you can setup your web application to use only the one from your application. Update your weblogic.xml file and add the following tag :
<prefer-web-inf-classes>true</prefer-web-inf-classes>

WebappclassLoader and StandardclassLoader jar conflict

I'm having an issue I believe is due to Tomcat, but I'm not sure where to go because I'm not too knowledgeable on the subject
The problem is, I have a couple of projects that use log4j, and recently when starting the server I get the following error:
log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [org.apache.catalina.loader.StandardClassLoader#a9ae05] whereas object of type
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
Doing some reading, I saw it pointed out that this was due to having several copies of the same jar.
Now, I believe that this is Tomcat's fault. I made a second server in Eclipse and the new server boots fine, so that sounds like a problem with the server configuration in the messed up one.
So I assume my old Tomcat is loading a jar file and this causes a conflict, whereas the new one doesn't have this jar file to cause the conflict in its configurations? My question is; how do I go about finding the culprit jar or configuration error?

Class Cast Exception When Same Jar is Included in WEB-INF/lib and CLASSPATH

I have a .jar file added to the CLASSPATH of the JBoss 5 startup (run.bat/run.sh) file. This is a dependency jar which is referred to from the servlet based application. If I use this setup, the servlet loads fine and works as expected. However, I noted that if I have the same jar in the servlet's WEB-INF/lib directory, I get a class cast exception as follows:
ERROR [STDERR] ERROR: com.idoox.wasp.ProtocolRepositoryImpl - Exception in protocolHandler soap, protocolHandler com.server.saaj.soap.SOAP11ProtocolHandler, class space root.wasp-impl.SOAP :
ERROR [STDERR] EXCEPTION:
ERROR [STDERR] com.systinet.saaj.soap.SOAP11ProtocolHandler cannot be cast to org.idoox.wasp.ProtocolHandler
ERROR [STDERR] java.lang.ClassCastException: com.server.saaj.soap.SOAP11ProtocolHandler cannot be cast to org.idoox.wasp.ProtocolHandler
This is not an issue since I won't have the jar in both places, but I'm just wondering why it is happening this way. Is this a class loading issue?
Thank You.
The jar file you are mentioning would be already available with JBoss. Whe you place it in the WEB-INF/lib; JBoss has already loaded the class from the jar available with JBoss and there is conflict with the class in the web-inf folder. Classes loaded by different classloaders are treated as different even if the classes are same. When you give in run.bat there is only one jar file loaded. JBoss loads this and there is no conflicting jars.

war works on tomcat but not on to jboss 6

I am trying to deploy a war to jboss 6 and i am getting the following exception that seems to envolve one of the jars in the war :webservices-rt.jar
this works fine in myeclipse-tomcat, so why is jboss rejecting the war?
14:45:03,286 ERROR [AbstractKernelController] Error installing to PostClassLoader: name=vfs:///C:/jboss-6/server/node01/deploy/altorweb.war state=ClassLoader mode=Manual requiredState=PostClassLoader: org.jboss.deployers.spi.DeploymentException: Error during deploy: vfs:///C:/jboss-6/server/node01/deploy/altorweb.war
...
Caused by: java.lang.Error: Error visiting "/C:/jboss-6/server/node01/deploy/altorweb.war/WEB-INF/lib/webservices-rt.jar/com/sun/xml/bind/v2/schemagen/XmlSchemaGenerator$Namespace.class"
at org.jboss.classloading.plugins.vfs.VFSResourceVisitor.visit(VFSResourceVisitor.java:268) [jboss-classloading-vfs.jar:2.2.0.Alpha7]
at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:407) [jboss-vfs.jar:3.0.0.CR5]
JBossAS6's implementation of unzip is somewhat** short on functionality. Basically it is quite easy to create zip archive which will create same Error on unzipping; that is during deployment of war/ear. To avoid this error allowed file names within archive should be in cp437 encoding. Remove/rename all non-english filenames from archive.
** zip container allows only Cp437 and UTF-8 encoded filenames by specification, but it lacks functionality to enforce this rule. And unfortunately it is quite easy to break it. So it isn't strict JBossAS6 error, but it is easy to see this error on JBoss as it uses non-java-defult unziping code.

Strange jboss console error

I'm creating additional module to already multi-module maven project. And for this one I want everything to be like in other modules(meaning dependencies) just to test hello world, then I'll go do some more complex stuff. And it does print hello world as it should when deployed onto jboss server, but I get some strange error on console, had anyone had similar experience? and how can I fix it? Here it is :
15:48:35,789 ERROR [STDERR] log4j:ERROR A "org.jboss.logging.appender.FileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
15:48:35,789 ERROR [STDERR] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
15:48:35,790 ERROR [STDERR] log4j:ERROR [BaseClassLoader#9a8d9b{vfszip:/C:/jboss-5.1.0.GA/server/default/deploy/new-module-0.0.1-SNAPSHOT.war/}] whereas object of type
15:48:35,790 ERROR [STDERR] log4j:ERROR "org.jboss.logging.appender.FileAppender" was loaded by [org.jboss.bootstrap.NoAnnotationURLClassLoader#506411].
15:48:35,790 ERROR [STDERR] log4j:ERROR Could not instantiate appender named "FILE".
Here is the part of Appender xml
http://pastebin.com/X7Dgdrki
First check your <server>/conf/jboss-log4j.xml for the configuration of the appender named FILE (and post it here if you can - that may give us more clues).
Further investigation reveals that org.jboss.logging.appender.FileAppender actually implements the interface org.apache.log4j.Appender. So this is apparently a classloader conflict. The same class definition (in this case org.apache.log4j.Appender), when loaded by two different classloaders, counts as two distinct classes for the JVM.
Is log4j.jar included in your war, or in your server/lib directory? If so, you could try removing it and see whether it resolves the issue.
Update: Actually the easiest possible solution is to simply change the type of the appender to org.apache.log4j.FileAppender in jboss-log4j.xml.
Regarding log4j.jar, what I mean is that if it is present in your war, it (and a copy of org.apache.log4j.Appender) gets loaded by the war classloader (BaseClassLoader#9a8d9b in your error message). And this causes the classloader conflict. So if you do not deploy log4j.jar with your war, the error may go away. This is related to Maven only in that the dependency is configured in your pom. For this little experiment, you can simply remove the log4j.jar from your war by hand; if this solves the issue, configure the log4j dependency in your pom as "provided", e.g.:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<scope>provided</scope>
</dependency>
If log4j.jar is not in your war, it might still be in the server/default/lib directory - please check that and if it is there, try to remove it.
We recently came across this problem. We tried the suggestions above and they did not work. So we handled the problem by replacing all log4j imports with a abstract logging interface (we chose org.apache.commons.logging for this) and removing the log4j from the depdenancies. Then what happens is the actual underlying logging implementation supports whatever JBoss has set. And if we want to move back to Tomcat (without JBoss) we can just add the log4j jar or whatever logger implementation back into the war.

Categories

Resources