1

I have an issue with the WAS Liberty classloader, nothing I do seem to fix it. The issue seems to be with log4j2, which I am using.

I'm running 16.0.0.4 (just upgraded from 8.5.5.9 where this issue also exist). I'm trying to create a webapp using Primefaces 6.0 which connects to Elasticsearch 5.1.1.

I have added the following dependency to maven:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>${library.elasticsearch.version}</version>
</dependency>

Somewhere along the road I need to do the following:

TransportClient client = new PreBuiltTransportClient(settings)
    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(HOST), PORT));

Debugging this line hits the following method call in Elasticsearch (class: org.elasticsearch.threadpool.ThreadPool line 203):

logger.debug("created thread pool: {}", entry.getValue().formatInfo(executorHolder.info));

This throws an java.lang.NoSuchMethodError:

org/apache/logging/log4j/Logger.debug(java/lang/String;java/lang/Object;)

Normally we use log4j 2.2, but I have included log4j2 2.7 as described here (Elasticsearch v5.0 uses 2.6.2, v5.1 uses 2.7): https://discuss.elastic.co/t/issue-with-elastic-search-5-0-0-noclassdeffounderror-org-apache-logging-log4j-logger/64262/2

I have also tried to make it "provided". I'm currently building a war file, but I also tried to do it as an ear, same result.

I came accoss this issue on the Elasticsearch 5-alpha: https://github.com/elastic/elasticsearch/issues/19415 Here they note that they wanted to create a server and therefore did not see log4j2 as a consern, but they suggest that you use the REST API instead (although, at the time of writing, this was not usable for Java developers).

So the question is, what do I do? Should I use the REST API (e.g. Jest (https://github.com/searchbox-io/Jest/tree/master/jest)) or ?...

The code I have works fine when running standalone outside Liberty.

UPDATE:

It seems like parts of Liberty does contain log4j v2.2:

class load: org.apache.logging.log4j.core.appender.routing.Route from: file:/C:/deploy/liberty/workarea/org.eclipse.osgi/60/data/cache/com.ibm.ws.app.manager_0/.cache/lib/log4j-core-2.2.jar
...

It loads a lot of classes from this jar, but not the one that I'm having trouble with - this is loaded from an app we have. I tried to bump the version inside our own app, but same issue.

sunlock
  • 212
  • 5
  • 17
  • you are probably picking up log4j from the parent WAS classloader, instead of your war's classloader. there is probably a way to specify parent-last classloading. – MeBigFatGuy Jan 10 '17 at 20:37
  • That is likely the case. You could set -verbose:class in the server's jvm.options file to get a print out of where classes are loaded. If the log4j classes are coming out of bundles in Liberty's lib directory, then it is getting loaded from the server's framework -- that might be a bug, but means that you could use [parentLast delegation](http://stackoverflow.com/questions/35367295/websphere-liberty-class-loading-parent-last-as-default) to work around it. Otherwise, the older log4j classes are getting loaded from your app or a shared library, and you should be able to remove them. – Andy McCright Jan 10 '17 at 21:32
  • I've just checked and unless you are using a z/OS specific feature log4j isn't in Liberty so changing to parent-last to avoid a Liberty shipped copy wouldn't be valid. Most likely you have two copies of log4j, as @AndyMcCright says -verbose:class would help track this down. If Elasticsearch have swagger for their REST API you could also use WDT to generate a Java REST client that you could use. This would probably be more in line with what elastic search recommend. – Alasdair Jan 10 '17 at 23:20
  • Currently running on Windows 7, but once ready it should be deployed on AIX. I'll give the -verbose:class a try. I did try the parent-last, just forgot to add it to the description. It didn't work, but maybe I did it wrong. – sunlock Jan 11 '17 at 06:35
  • I updated with info from the -verbose:class. I'll keep the issue open for a few days to see if any new ideas turn up. – sunlock Jan 11 '17 at 18:59

0 Answers0