Search code examples
apachejbossjarpojoapache-httpclient-4.x

Apache HttpClient inside JAR looking for JBoss reference?


I am using the Apache HttpClient libs to handle my communication with an API. All of my code compiles and runs without error when I unit test the exploded code. However, when I JAR my source and test the code in a isolated integration test I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logmanager/Logger$AttachmentKey
    at org.slf4j.impl.Slf4jLoggerFactory.<clinit>(Slf4jLoggerFactory.java:31)
    at org.slf4j.impl.StaticLoggerBinder.getLoggerFactory(StaticLoggerBinder.java:33)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:240)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:208)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
    at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:159)
    at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:178)
    at opart.api.client.trasnsport.Transport.get(Transport.java:81)
    at opart.api.client.dao.objects.ObjectsDao.getInterestingObjects(ObjectsDao.java:70)
    at opart.api.client.OpartApiClient.getInterestingObjects(OpartApiClient.java:79)
    at ApiTest.interesting(ApiTest.java:32)
    at ApiTest.main(ApiTest.java:21)
Caused by: java.lang.ClassNotFoundException: org.jboss.logmanager.Logger$AttachmentKey
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    ... 14 more

When I try to instantiate a DefaultHttpClient object thusly:

DefaultHttpClient defaultHttpClient = new DefaultHttpClient();

The libs I have included in my JAR are:

  • guava-r09.jar
  • commons-logging-1.1.1.jar
  • httpclient-4.1.2.jar
  • httpcore-4.1.2.jar
  • gson-1.7.1.jar

Any ideas as to why it is trying to reference JBoss?


Solution

  • The solution I found was to use the zipfileset ant target which safely explodes the contents of the JARchives inside the root of the uber JAR.