Error running Java EE application with GlassFish: NoClassDefFoundError: org/apache/commons/logging/LogFactory

51 views Asked by At

When trying to run a Java EE application with GlassFish, I encounter the following error on the server:

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.apache.http.conn.ssl.DefaultHostnameVerifier.<init>(DefaultHostnameVerifier.java:72)
    ...
...
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at dynamics365.TokenGenerator.ejecutarTokenGenerator(TokenGenerator.java:62)
    at sessionBeans.ParametroFacade.buscarCliente(ParametroFacade.java:103)
        at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:808)
    ...

What I've tried:

  • I have reviewed the project configuration to make sure all dependencies are configured correctly.
  • I have removed the use of Apache Commons Logging as it appears to be the cause of the problem.
  • I have cleaned and rebuilt the project to make sure there are no outdated build artifacts.
  • I've reviewed the project structure and GlassFish server configuration to ensure everything is in order.

Wait:

I am looking for help to fix this error and understand why it occurs. Is there something I'm overlooking in my configuration or dependency management? How can I resolve this issue and run my application without this error?

2

There are 2 answers

0
Miguel On BEST ANSWER

What I did was reload all the JAR into the lib of the payara domains, restart it and from there, clean and build the project and it worked.

0
Stephen C On

I am looking for help to fix this error and understand why it occurs.

It is happening because something in your application and/or its dependencies depends on that LogFactory class. That is indisputable.

As best as I can tell, your class TokenGenerator is still making use of Apache Commons Logging. That is what the stacktrace seems to say.

So either:

  1. the stacktrace is out of date,
  2. the copy of TokenGenerator.class that is being used at runtime is out of date, or
  3. you forgot to update TokenGenerator.java.

On the other hand, if TokenGenerator.java is not your code, then you need to modify the project configuration so that the JAR file for Apache Commons Logging is present at runtime!

Is there something I'm overlooking in my configuration or dependency management?

Quite possibly. For example, you have only told us what you think you did and checked. You haven't shown us the configuration or dependency management stuff, etc.

How can I resolve this issue and run my application without this error?

Either remove the remaining references to the dependency from your application and its (transitive!) dependencies that must exist, or make sure that the requisite JAR is included.


(I am assuming that there aren't other exceptions that you haven't told us about; i.e. exceptions resulting from failed static initialization that happened before this one. A static initialization failure for a class will render other classes uninitializable, and that can result in cascading exceptions.)