1

When running a rest service in native mode I get a class org.apache.commons.logging.impl.LogFactoryImpl not found exception. It's running fine with the openjdk mode.

I have write a small service rest to repoduce the problem.

The service Rest :

package org.acme.rest.json;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 

import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.deployment.annotations.BuildStep;

@Path("/logs")
public class LogResource {
   private Log log = LogFactory.getLog(LogResource.class);
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        log.info("jello");
        return "hello";
    }
}

When invoking this file I get


xception handling request 04cf25a8-aafb-4b2a-978e-47a24009b22d-1 to /logs: org.jboss.resteasy.spi.UnhandledException: org.apache.commons.logging.LogConfigurationException: java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl (Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl)

2 Answers 2

5

Following your advice, I got it running using the following config : pom.xml

    <build>
        <plugins>
          <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>native-image</goal>
                </goals>
                <configuration>
                  <enableHttpUrlHandler>true</enableHttpUrlHandler>
                 <additionalBuildArgs>-H:ReflectionConfigurationFiles=/home/dev/repo/quarkus-mailbox-native//src/main/resources/reflectconfig.json,-H:DynamicProxyConfigurationFiles=/home/dev/repo/quarkus-mailbox-native/src/main/resources/dynamicproxy.json</additionalBuildArgs>
                </configuration>
              </execution>
            </executions>
          </plugin>

reflect.json

[
    {
      "name" : "org.apache.commons.logging.impl.LogFactoryImpl",
      "allDeclaredConstructors" : true,
      "allPublicConstructors" : true,
      "allDeclaredMethods" : true,
      "allPublicMethods" : true,
      "allDeclaredClasses" : true,
      "allPublicClasses" : true
    },
    {
        "name" : "java.lang.String",
        "allDeclaredConstructors" : true,
        "allPublicConstructors" : true,
        "allDeclaredMethods" : true,
        "allPublicMethods" : true,
        "allDeclaredClasses" : true,
        "allPublicClasses" : true
      },
      {
        "name" : "org.apache.commons.logging.LogFactory",
        "allDeclaredConstructors" : true,
        "allPublicConstructors" : true,
        "allDeclaredMethods" : true,
        "allPublicMethods" : true,
        "allDeclaredClasses" : true,
        "allPublicClasses" : true
      },
      {
        "name" : "org.apache.commons.logging.impl.SimpleLog",
        "allDeclaredConstructors" : true,
        "allPublicConstructors" : true,
        "allDeclaredMethods" : true,
        "allPublicMethods" : true,
        "allDeclaredClasses" : true,
        "allPublicClasses" : true
      }
]

Thanks for your help.

X.

0
3

Please use JBoss Logging instead of Commons Logging:

private static final Logger LOGGER = Logger.getLogger(LogResource.class.getName());

with Logger being org.jboss.logging.Logger.

JBoss Logging setup is fully taken care of by Quarkus.

If you want to use another logging facility, you will need to do the setup yourself. In your case, you would need to register LogFactoryImpl for reflection to make it work with GraalVM.

If you really don't want to use JBoss Logging (whih is a bad idea in my opinion as it has all the features you need), you have to follow the instructions of the GraalVM documentation: https://github.com/oracle/graal/blob/master/substratevm/Reflection.md#manual-configuration .

I recommend using the @AutomaticFeature as you just need to add a class in your application.

If you go the JSON config way, you can provide some additional arguments via <additionalBuildArgs> in the configuration of the Maven native-image phase.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.