0

I'm trying to do log rotation in Tomcat 8.5. I have followed log4j process by referring URL https://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j . But after following the process mentioned in the URL I'm unable to open localhost, it's giving 404 error and the log is like below. Can anyone help me out in this?

"ERROR org.apache.catalina.core.ContainerBase- ContainerBase.addChild: start: 
    org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1858)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: org/apache/juli/WebappProperties
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4943)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        ... 10 more
    Caused by: java.lang.ClassNotFoundException: org.apache.juli.WebappProperties
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 23 more"
Surekha
  • 333
  • 1
  • 5
  • 17
  • Can you summarize what you did: did you just change `logging.properties`? It seems like you removed `tomcat-juli.jar` from Tomcat's classpath or from the `bin` folder. – Piotr P. Karwasz Apr 29 '21 at 05:50
  • Here I have removed the logging .properties and also overwrite juli jar with another one which support log4j concept. – Surekha Apr 29 '21 at 06:15

1 Answers1

0

You are looking at the documentation for Tomcat 7.0. The documentation for your version is available here.

The tomcat-juli-extras you downloaded for Tomcat 7.0 does not work with Tomcat 8.5 and there is no tomcat-juli-extras provided for Tomcat 8.5. In Tomcat 8.5 is no longer necessary (and possible) to physically replace the default JULI implementation.

Restore the tomcat-juli.jar that came with Tomcat to resolve the error.

If you want to Log4j2 as the server's logging system, follow the instructions in Log4j2 documentation. Basically you need to:

  1. Create a folder for Log4j2 libraries and configuration. Let's say $CATALINA_BASE/log4j/lib and $CATALINA_BASE/log4j/conf.
  2. Download log4j-api, log4j-core and log4j-appserver (the latter contains an implementation of the logging API in tomcat-juli.jar) into log4j/lib,
  3. Add a configuration file in you favorite format to log4j/conf (cf. documentation),
  4. Add the three libraries from point 2 and the log4j/conf folder to the server's system classloader. This step depends on how do you start Tomcat. If you use catalina.sh/startup.sh (on Unixes) add to $CATALINA_BASE/setenv.sh (create it if necessary):
CLASSPATH="$CATALINA_BASE/log4j/lib/*.jar:$CATALINA_BASE/log4j/conf"
  1. Restart the server.
Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • Thank you for the reply. Can you please explain how to do step 4 in windows? Do I need to create setenv.bat file? – Surekha Apr 29 '21 at 11:18
  • On Windows you probably use the Procrun (see picture in [this answer](https://stackoverflow.com/a/62346565/11748454)). There is a text field there to add these entries to the classpath. – Piotr P. Karwasz Apr 29 '21 at 11:43