ClassLoader classcastexception with activemq client - java

I have been struggling with this problem for a while now, decided to ask the community, hoping to get some hints/answers.
I am using tomcat 7.0.54 as my J2EE container which has a WAR deployed with dependency on activemq-all.
Along with the above, I'm also placing a jar in the classpath to register a listener programmatically, by implementing the ServletContainerInitializer interface. This initializes a simple implementation of an active mq client, JvmMessageProducerImpl (I have activemq-client as a dependency in the pom).
With the above setup, when i try to start tomcat, i get the below exception. It seems that instead of loading the classes independently, the listener which is called when the web application starts, is finding an existing instance of TcpTransportFactory and throwing the ClassCastException. I have read the classloader manual for tomcat multiple times, and my understanding is that each of the war files should have independent Class loaders - but dont completely understand why the exception is being thrown?
javax.jms.JMSException: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [tcp]
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:317)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:330)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:251)
at com.monitoreverywhere.jvmmon.mq.JvmMessageProducerImpl.setup(JvmMessageProducerImpl.java:66)
at com.monitoreverywhere.jvmmon.mq.JvmMessageProducerImpl$Runner.run(JvmMessageProducerImpl.java:163)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.io.IOException: Transport scheme NOT recognized: [tcp]
at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:27)
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:181)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:63)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:315)
... 5 more
Caused by: java.lang.ClassCastException: org.apache.activemq.transport.tcp.TcpTransportFactory cannot be cast to org.apache.activemq.transport.TransportFactory
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:178)
... 7 more

Related

ExtendedLogService does not appear to start

I am attempting to run an Eclipse 3.x application using Equinox in Neon as initiated in this question.
It appears that my remaining issue is that the LogReaderService appears to not be available, as the second line below in org.eclipse.core.internal.runtime.InternalPlatform.getLog() appears to throw a NullPointerException:
ExtendedLogReaderService logReader = logReaderTracker.getService();
logReader.addLogListener(result, result);
An implementation of this class can be found in org.eclipse.osgi, which I am launching the application with. For whatever reason, though, the service is null, which causes a number of plug-ins to throw exceptions when logging since many of the plug-ins rely on getting the Logging service from the Activator.
Since org.eclipse.osgi contains the implementation in its internals, I assumed that it would also register the service. That does not appear to be the case. I have also tried including log4j and org.apache.felix.log and neither appear to resolve this problem.
There must be something simple that is missing here to get the LogService to start? Here's the stack trace:
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.core.resources (44).
at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:116)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:529)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:36)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:419)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 20 more
Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start() of bundle org.eclipse.core.resources.
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:795)
at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:724)
at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:932)
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:309)
at org.eclipse.osgi.container.Module.doStart(Module.java:581)
at org.eclipse.osgi.container.Module.start(Module.java:449)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:470)
at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
... 29 more
Caused by: java.lang.NullPointerException
at org.eclipse.core.internal.runtime.InternalPlatform.getLog(InternalPlatform.java:353)
at org.eclipse.core.runtime.Platform.getLog(Platform.java:976)
at org.eclipse.core.internal.utils.Policy.log(Policy.java:159)
at org.eclipse.core.internal.resources.Workspace.setCrashed(Workspace.java:2302)
at org.eclipse.core.internal.resources.SaveManager.restoreSnapshots(SaveManager.java:963)
at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:720)
at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1587)
at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2399)
at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2156)
at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:464)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:774)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:767)
... 36 more
I also added
Require-Capability: osgi.service;filter:="(objectClass=org.osgi.service.log.LogService)";effective:=active
To one of the dependent bnd files. This did not appear to solve the problem.
Edit: Because the OSGI Framework is set to org.eclipse.osgi in the bndrun file, is that preventing the logging from getting initialized? I have also tried adding org.apache.commons.logging as well as osgi.enroute.equinox.log.adapter and I am still getting NPEs when anything attempts to log. The org.eclipse.osgi bundle is already considered running by the time the RCP plugins get activated... yet there is no ExtendedLogReaderService. Do I need to find a way to install Felix as the Core Runtime in order to make org.eclipse.osgi able to get started by the framework in order for the ExtendedLogReaderServiceImpl to get registered?
I have found numerous examples of how to listen for the LogService... I'm not seeing how to start the ExtendedLogService.
Edit 2: I am able to suppress the LogService nulls issue by registering dummy ExtendedLogService implementations.
The problem has been resolved (finally), revisiting this now that our build system is in place the solution was likely that osgi.enterprise was not a Required-Bundle which also caused caused our OSGI-JDBC services to not work properly when testing the deployed target platforms.
Additionally, our primary RCP plug-in (containing the Application class, etc.) did not have a Bundle-ActivationPolicy: lazy clause in the *.bnd files used to generate the MANIFEST.MF file which lead to some other problems.
Just in case anyone else runs into such problems.

MySQL MissingResourceException when running .jar from memory HikariCP

I've created an client program which uses Netty in order to download a .jar through a TCP socket and creates a new instance of JarInputStream
When I'm initializing the program everything loads up find untill connecting the database when it throws an MissingResourceException.
The original jar (The one that gets send trough netty) runs fine when normally ran via terminal / commandprompt. I don't think it is an issue in my code atleast.
I'm using HikariCP for database pooling and when connecting to the database it throws me this stacktrace:
Caused by: java.lang.ExceptionInInitializerError
at com.mysql.jdbc.ConnectionPropertiesImpl.<clinit>(ConnectionPropertiesImpl.java:586)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at com.zaxxer.hikari.util.UtilityElf.createInstance(UtilityElf.java:117)
at com.zaxxer.hikari.pool.PoolUtilities.initializeDataSource(PoolUtilities.java:110)
at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:157)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
Caused by: java.lang.RuntimeException: Can't load resource bundle due to underlying exception java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale nl_NL
at com.mysql.jdbc.Messages.<clinit>(Messages.java:54)
... 38 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale nl_NL
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:721)
at com.mysql.jdbc.Messages.<clinit>(Messages.java:52)
... 38 more
I'm using:
mysql-connector-java : 5.1.37
HikariCP-java6 : 2.3.12
I can confirm that the LocalizedErrorMessages.properties file is indeed in com/mysql/jdbc.
Classloader I'm using: http://pastebin.com/9VsV32Yg
The original jar runs fine when executed from terminal / commandprompt.
The entrypoint in the original jar gets correctly executed in my TCP application as I can see startup output from it appearing in the console.
Hope someone knows whats causing the issue.
You need to implement public URL getResource(String name) and various other resource API. A ClassLoader does more than just load classes, it also provides access to other resources contained within the JAR.

Initialize Hibernate SessionFactory in a EJB mdb?

I am trying to deploy an MDB in WAS 8.5. The session Factory is being initialized in ejbCreate method. When I try to deploy the application ejb loads successfully and then it shuts down the Queue Activation and gives the following exceptions-
I am not using any framework or MAven for built so all the jars and config files have been added to the classpath as in a Standalone Java Application.
Here are the Hibernate and JAVAEE Jars I am using-
antlr-2.7.7
c3p0-0.9.1
commons-collections-3.2.1
commons-logging-api-1.1.3
dom4j-1.6.1
hibernate-c3p0-4.1.5.Final
hibernate-commons-annotations-4.0.1.Final
hibernate-core-4.1.5.Final
hibernate-entitymanager-4.1.5.Final
hibernate-envers-4.1.5.Final
hibernate-jpa-2.0-api-1.0.1.Final
javassist-3.15.0GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final
jms-1.1
log4j-1.2.15
MySQL-connector-java-5.1.22
slf4j-api-1.6.1
javaee.jar
javaee-api-6.0
Here is the exception stacktrace from system logs
EJB threw an unexpected (non-declared) exception during invocation of method "onMessage".Exception data:
javax.ejb.EJBException: MDB PostConstruct failure; nested exception is:
java.lang.Exception: See nested Throwable
at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:472)
at com.ibm.ejs.container.MessageDrivenBeanO.initialize(MessageDrivenBeanO.java:427)
at com.ibm.ejs.container.BeanOFactory.create(BeanOFactory.java:147)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1238)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1356)
at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate
(UncachedActivationStrategy.java:88)
at com.ibm.ejs.container.activator.Activator.preInvokeActivateBean(Activator.java:615)
at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:4205)
at com.ibm.ejs.container.EJSContainer.preInvokeMdbActivate(EJSContainer.java:3709)
at com.ibm.ejs.container.MessageEndpointHandler.beforeDelivery
(MessageEndpointHandler.java:1449)
at com.ibm.ejs.container.MessageEndpointHandler.invokeMessageEndpointMethod
(MessageEndpointHandler.java:866)
at com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:832)
at $Proxy50.beforeDelivery(Unknown Source)
at com.ibm.mq.connector.inbound.AbstractWorkImpl.run(AbstractWorkImpl.java:188)
at com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:608)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1783)
Caused by: java.lang.Exception: See nested Throwable
at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:470)
... 15 more
Caused by: java.lang.NoClassDefFoundError: org.hibernate.HibernateException
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:85)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:162)
at com.hps.superenrollment.ejbmodule.SuperEnrollmentRequestMDB.ejbCreate
(SuperEnrollmentRequestMDB.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor
(InterceptorProxy.java:232)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed
(InvocationContextImpl.java:559)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle
(InvocationContextImpl.java:273)
at com.ibm.ejs.container.MessageDrivenBeanO.initialize(MessageDrivenBeanO.java:411)
Please help me as I am completely lost on what is going wrong here .
The NoClassDefFoundError indicates that some Hibernate class is not in your class-path. Are you sure you have all dependency jars in your classpath (including the jars which are needed at runtime)?
The exception indicating that you should use a PostConstructor method instead of the bean class constructor indicates that you should use the ejbCreate() method. This is the recommended location to initialise and load dependencies of your MDB as it is called by one single thread of the ejb container and ensures that the MDB has been fully constructed before you execute the configuration in the ejbCreate(). It is somewhat similar to the init method in a servlet which is also guaranteed to be called single threaded by the servlet container.

Issue in creating an instance of JAX-WS client to access the service

Iam new to Webservices.
Iam trying to create a JAX- WS client from a WSDL file . Using RAD 8.0 , I generated the classes including the proxy ,SEI and the Webservice client .Now iam trying to hit the exposed webservice methods as a standalone application .
I have added jaxws-rt-2.1.4.jar to the classpath also .
From the main class ,if i try to create an instance of the client to access the service iam getting the following error .
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:227)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1345)
at java.util.ServiceLoader$ServiceIterator.next(ServiceLoader.java:195)
at javax.xml.ws.spi.Provider.getProviderUsingServiceLoader(Provider.java:146)
at javax.xml.ws.spi.Provider.provider(Provider.java:106)
at javax.xml.ws.Service.<init>(Service.java:57)
at com.royalbank.wcm_ap.ws_client.rbcauth.v1.AnPAuth.<init>(AnPAuth.java:35)
at com.royalbank.wcm_ap.ws_client.rbcauth.v1.TestClass.main(TestClass.java:53)
Caused by: javax.xml.ws.WebServiceException: Error creating JAXBContext for W3CEndpointReference.
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:222)
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:218)
at java.security.AccessController.doPrivileged(AccessController.java:203)
at com.sun.xml.ws.spi.ProviderImpl.getEPRJaxbContext(ProviderImpl.java:217)
at com.sun.xml.ws.spi.ProviderImpl.<clinit>(ProviderImpl.java:88)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:205)
... 8 more
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.ibm.xml.xlxp2.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:207)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:401)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:618)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:565)
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:220)
Am i missing something here with regard to the configurations ? thanks in advance :)
The Missing class "com.ibm.xml.xlxp2.jaxb.JAXBContextFactory" is available in the jar "com.ibm.jaxws.thinclient_8.5.0.jar" which will be available in the server runtime directory for Websphere App server : C:\Program Files\IBM\WebSphere\AppServer\runtimes.
Please include this jar for compile purpose only and donot include this in your WAR or EAR as it will conflict with your server runtime library jar.
For server WAS 8.0 the path jar would be "com.ibm.jaxws.thinclient_8.0.0.jar".

Why would Java classloading fail on Linux, but succeed on Windows?

I've got a Java web application (using Spring), deployed with Jetty. If I try to run it on a Windows machine everything works as expected, but if I try to run the same code on my Linux machine, it fails like this:
[normal startup output]
11:16:39.657 INFO [main] org.mortbay.jetty.servlet.ServletHandler$Context.log>(ServletHandler.java:1145) >16> Set web app root system property: 'webapp.root' = [/path/to/working/dir]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:151)
at org.mortbay.start.Main.start(Main.java:476)
at org.mortbay.start.Main.main(Main.java:94)
Caused by: java.lang.ExceptionInInitializerError
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:129)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:51)
at org.mortbay.jetty.servlet.WebApplicationContext.doStart(WebApplicationContext.java:495)
at org.mortbay.util.Container.start(Container.java:72)
at org.mortbay.http.HttpServer.doStart(HttpServer.java:708)
at org.mortbay.util.Container.start(Container.java:72)
at org.mortbay.jetty.Server.main(Server.java:460)
... 7 more
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;#15311bd for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;#15311bd for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at org.springframework.util.SystemPropertyUtils.(SystemPropertyUtils.java:42)
... 14 more
Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;#15311bd for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:413)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
... 18 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Category
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:410)
... 19 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 24 more
[shutdown output]
I've run the app with java -verbose:class, and according to that output, org.apache.log4j.Category is loaded from the log4j JAR in my /WEB-INF/lib, just before the first exception is thrown.
Now, the Java versions on the two machines are slightly different. Both the machines have Sun's java, the Linux machine has 1.6.0_10, while the Windows machine has 1.6.0_08, or maybe 07 or 06, I can't remember the exact number right now, and don't have the machine at hand. But even though the minor versions of the Javas are slightly different, the code shouldn't break like this. Does anyone understand what's wrong here?
You must understand that a classloader can't see everything; they can only see what a parent classloader has loaded or what they have loaded themselves. So if you have two classloaders, say one for Jetty and another for your webapp, your webapp can see log4j (since the JAR is the WEB-INF/lib) but Jetty's classloader can't.
If you manage to make a class available to Jetty (for example something in the DB layer) which uses log4j but which ends up running in the context (and classloader) of Jetty, you will get an error.
To debug this, set a breakpoint in org.springframework.web.util.Log4jWebConfigurer.initLogging(). If you can, copy the source of this class into your project (don't forget to delete it afterwards) and add this line:
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Have a look at the cl object in your debugger. That should give you some information who created it. My guess is that this is the classloader from Jetty.
[EDIT] Note that you get in a different mess if you have log4j in both classloaders: In this case, you will have two classes with the same name which create objects which are not assignment compatible! So make sure there is only a single instance of this jar or that instances of log4j will never be passed between the two contexts (which is usually not possible).
This seems like a classic classloader problem. It could be due to another web app being loaded first which also uses log4j but a version that is different to the one used by the app you are testing. The classloader uses the first version of the class it finds. The server class loading policy can usually be changed in the config files. Sorry I am a bit rusty on this but maybe it can point you in the correct direction.
Make sure there are no other installed apps on the web server,
Make sure the log4j being loaded is the correct version,
Make sure you don't have a log4j lurking somewhere in the classpath of the server.
HTH
You're using the same WAR on both machines? Have you checked if the WAR files are identical (no transfer errors occured)?
Some random things to consider:
(1) Check if there are any other versions of log4j floating around on the linux instance, outside of the web-app directories?
(2) Is apache commons logging being used at all? You might want to consider SLF4J instead?
(3) Did the JAR/WAR become corrupt in some way - was it FTP'ed in ASCII or Binary?
(4) Print out the classloader hierarchy in each case, just to see if there are any discrepancies?
Even though the original problem was solved for the asker, I'll point out that a common source of problems when running the same code on Windows vs Linux (or Unix) is case-sensitivity issues. Windows ignores case while Linux or Unix is case-sensitive. This has bitten me more than once.
So if you specify a jar or directory on the classpath, but it isn't the right case then it will fail on Linux but succeed on Windows. This can also be the source of FileNotFoundExceptions.
Had the same problem and found an easy solution/workaround:
In Eclipse in Preferences > Java > Installed JREs, select the JRE > Edit and Add External JARs... and browse to your log4j.jar.
The other workaround is to add log4j.jar to every launch definition in Classpath tab.

Categories