Rodrigo
Rodrigo

Reputation: 37

java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object - Tomcat 8

I am getting this exception:

java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
            at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:142)
            at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
            at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)

Why? There are two jars containing the class Logger. The jars are:

-jboss-logging-spi and jboss-logging

Jboss-logging-spi.jar is a transitive dependency of the jbosscache-core.jar and unfortunately it gets loaded first by Tomcat 8.

What is the best way to fix this? Is it possible to control the order in which the .jars are loaded by Tomcat?

Additional information:

-The current .war file which I can't get it working on the new server(Ubuntu) it is working on the old server(OpenSuse).

Upvotes: 2

Views: 535

Answers (2)

Christopher Schultz
Christopher Schultz

Reputation: 20882

Explicit JAR-ordering can be accomplished in Tomcat via abusing the resources facility in Tomcat. I'm not going to give a complete answer, here, because (a) it's highly non-recommended and (b) you'd better really know what you are doing in order to do it.

So, briefly:

  1. Read all about resources
  2. Use <PreResources> to force a library or libraries to the front of the line
  3. Reconsider whether you really want to do this, or just fix the initial problem

Upvotes: 0

Olaf Kock
Olaf Kock

Reputation: 48087

What is the best way to fix this?

Eliminate the duplicate classes. Period. There's no other recommendation. Masking the problem through class loading order will have a similar problem pop up later, making maintenance harder next time.

One application should never contain two conflicting implementations (or even two identical implementations) of the same class. If one of the classes is on the (appserver-) global classpath: Remove it from there.

Upvotes: 2

Related Questions