6
votes

I am running into some issues with trying to load libs from my application instead of what comes with JBoss.

I am trying to make use of the latest and greatest SLF4J in my application and in doing so I am getting the following messages:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [vfszip:/C:/devtools/workspace/g2/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server1302541739184/deploy/ecotrakEar.ear/ecotrak.war/WEB-INF/lib/slf4j-log4j12-1.6.1.jar/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [vfszip:/C:/devtools/jboss-5.1.0.GA/common/lib/slf4j-jboss-logging.jar/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

In my application I have the following jars located in my WAR lib directory:

  • jul-to-slf4j-1.6.1.jar
  • slf4j-api-1.6.1.jar
  • slf4j-log4j12-1.6.1.jar

My project is deployed as an EAR with a WAR. All libraries reside in the WAR.

Based on some research it has been suggested that for JBoss 5.1 that a jboss-classloading.xml file be created. I have created one for my EAR:

<classloading xmlns="urn:jboss:classloading:1.0"
  name="ecotrak.ear"
  domain="ecotrak.ear"
  export-all="NON_EMPTY"
  import-all="true"
  parent-first="false">
</classloading>

This identifies that the EAR file is to be loaded first.

I have also created one for my WAR:

<classloading xmlns="urn:jboss:classloading:1.0"
  name="ecotrak.war"
  domain="ecotrak.war"
  parent-domain="ecotrak.ear"
  top-level-classloader="true"
  export-all="NON_EMPTY"
  import-all="true"
  parent-first="true">
</classloading>

With this configuration I am getting the following error in the startup logs:

11:18:07,949 ERROR [[/ecotrak]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.trace(SLF4JLocationAwareLog.java:107)

What is the correct way in order to have jars from my project be loaded before JBoss's?

2

2 Answers

0
votes

You should use something like as:

<jboss-app>
   <loader-repository> 
   com.example:archive=unique-archive-name 
   </loader-repository> 
</jboss-app>

in META-INF/jboss-app.xml to define own classloader.

We use it for own Hibernate jars deployement inside application.

See https://community.jboss.org/wiki/ClassLoadingConfiguration for details

0
votes

I know this thread is very old, but I had a similar problem today so I think the problem itself may happen yet with someone.

I needed to run two similar 'ear' in different contexts, with the same package/class names inside its subprojects (JBoss 5.1.0 GA).

So after some research, and attempts to use the full 'jboss-classloading.xml' version provided here and by some blogs, I used a simpler version of 'jboss-classloading.xml' file on my EAR (with no specific 'jboss-classloading.xml' for my subprojects JAR/WAR/etc.):

<classloading xmlns="urn:jboss:classloading:1.0"
          domain="IsolatedDomain"
          export-all="NON_EMPTY"
          import-all="true">
</classloading>

This was included in my EAR project META-INF directory. Hope this helps others with similar problems.

I got the working version from this site:

https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Microcontainer_User_Guide/sect-JBoss_Microcontainer_User_Guide-The_ClassLoading_Layer-ClassLoading.html