aspose file tools*
The moose likes Struts and the fly likes Log4j\Layout error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Log4j\Layout error" Watch "Log4j\Layout error" New topic
Author

Log4j\Layout error

RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi all,
I am trying to run the example from Sprinkle some ajax magic into Struts. But I am getting this error repeatedly. I am using Tomcat 5.0.30 and Struts 1.2.9 version and JDK 1.4.
I have already the classpath set with the particular JAR adn also the classes are in the classpath. Tried to use many versions of log4j, but no luck I also have checked the Layout class, it exists for all versions..
Classpath:

C:\j2sdk1.4.2_04\lib\*.jar;C:\eclipse\startup.jar;C:\oracle\ora92\jdbc\lib\classes111.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\struts.jar;C:\Program Files\Apache Software Foundation\Tomcat .0\common\lib\servlet-api.jar;D:\iReport-1.2.5\lib\jasperreports-1.2.5.jar;D:\anks\eclipse\plugins\com.jasperassistant.designer.core_1.24.0\lib\jasperreports-1.2.4.jar;D:\anks\examples\jasperreports-1.2.5\lib\*.jar;C:\New Folder\reports-demo\JReportsEAR\JReportsWEB\WEB-INF\lib\*.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\commons-digester-1.7.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jakarta-bcel-20050813.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\struts-non-ajax\WEB-INF\lib\log4j-1.2.13.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\struts-non-ajax\struts-non-ajax\WEB-INF\classes\;.

Error:
-------------------------------------------

SEVERE: Error deploying web application directory struts-non-ajax
java.lang.NoClassDefFoundError: org/apache/log4j/Layout
at org.apache.commons.logging.impl.Log4jFactory.getInstance(Log4jFactory
.java:153)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactory
Impl.java:285)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:409)
at org.apache.commons.digester.Digester.<init>(Digester.java:304)
at org.apache.catalina.startup.DigesterFactory.newDigester(DigesterFacto
ry.java:71)
at org.apache.catalina.startup.TldConfig.createTldDigester(TldConfig.jav
a:408)
at org.apache.catalina.startup.TldConfig.tldScanStream(TldConfig.java:50
8)
at org.apache.catalina.startup.TldConfig.tldScanTld(TldConfig.java:547)
at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:301)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
282)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:80
7)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)

at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDep
loyer.java:277)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:701)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
80)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:231
3)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
-------------------------

Can anyone please suggest where I am doing wrong.
Regards,
Roshani


Regards,<br />Roshani
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest you remove the struts.jar file and its associated commons-xxx.jar files from your Tomcat shared classpath and simply put them in the WEB-INF/lib directory. I'd also suggest that you put your log4j.jar file in WEB-INF/lib. This way you are assured that the commons logging and log4j will be loaded by the same ClassLoader.


Merrill
Consultant, Sima Solutions
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Please HELLLPPPP!!!

Hi Merrill,
As you had suggested, I did the same. I also uninstalled Tomcat and ran it again. But ..

My classpath:

C:\j2sdk1.4.2_04\lib\*.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\struts-non-ajax\WEB-INF\classes;.

The libs in tomcat/ commoms/lib
ant.jar
ant-launcher.jar
jasper-compiler.jar
jasper-runtime.jar
jsp-api.jar
naming-common.jar
naming-factory.jar
naming-java.jar
naming-resources.jar
servlet-api.jar
tools.jar


The struts-non-ajax lib has:
antlr.jar
commons-beanutils.jar
commons-collections-3.1.jar
commons-dbcp-1.2.1.jar
commons-digester.jar
commons-el.jar
commons-fileupload.jar
commons-logging.jar
commons-pool-1.2.jar
commons-validator.jar
jakarta-oro.jar
log4j-1.2.8.jar
struts.jar

error:
------------------------------

SEVERE: Error deploying web application directory struts-non-ajax
java.lang.NoClassDefFoundError: org/apache/log4j/Layout
at org.apache.commons.logging.impl.Log4jFactory.getInstance(Log4jFactory
.java:153)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactory
Impl.java:285)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:409)
at org.apache.commons.digester.Digester.<init>(Digester.java:304)
at org.apache.catalina.startup.DigesterFactory.newDigester(DigesterFacto
ry.java:71)
at org.apache.catalina.startup.TldConfig.createTldDigester(TldConfig.jav
a:408)
at org.apache.catalina.startup.TldConfig.tldScanStream(TldConfig.java:50
8)
at org.apache.catalina.startup.TldConfig.tldScanTld(TldConfig.java:547)
at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:301)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
282)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:80
7)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)

at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDep
loyer.java:277)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:701)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
80)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:231
3)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
----------------------------------------------------

Still I get the error. Infact It is working fine on a colleague's machine. Should I reinstall the JDK???Please help!!

Regards,
Roshani
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Simce the error seems to be happening as Tomcat is starting up, try putting the log4j.jar file in server/lib.
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Originally posted by Merrill Higginson:
Simce the error seems to be happening as Tomcat is starting up, try putting the log4j.jar file in server/lib.


Hi Merrill,
If i put the log4j file in the server/lib, Tomcat service starts and stops automatically. I am unable to run the server.

Secondly, if i remove the jar from the lib of all the applciations, the application is deployed, but when i run it tomcat gives the foll error.

-----------------
root cause

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
ajaxsample.SampleAction.<init>(SampleAction.java:21)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:274)
java.lang.Class.newInstance0(Class.java:308)
java.lang.Class.newInstance(Class.java:261)
org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:145)
org.apache.struts.action.RequestProcessor.processActionCreate(RequestProcessor.java:282)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:220)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

-----------------

The SampleAction.java is as follows:

public class SampleAction extends Action {

/** Logger for this class and subclasses */
protected final Logger log = Logger.getLogger(getClass());


public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {

log.debug("SampleAction.execute()");

//Local Variables

//Log the incoming values
Enumeration myLoop= request.getParameterNames();
String tmpObject;

log.debug("======");
while (myLoop.hasMoreElements()){
tmpObject = ""+myLoop.nextElement();
log.debug("Incoming key:"+tmpObject+" value:"+request.getParameter(tmpObject));
}
log.debug(inForm);
log.debug("======");
//otherwise , return null
log.info("returning to the welcome page");
return mapping.findForward("welcome");
} // End execute()
} // End class

Now i am confused, at deployment it gives error of /Layout class and now it gives the error for /Logger ...??? This problem exists for another project on WAS also.

I am unable to get any lead.. Any help would be deeply appreciated.

Regards,
Roshani
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi all,
i thought I should share the solution with all you. Instead of putting the log4j in the server/lib or the commons/lib of Tomcat, i put it in the C:\j2sdk1.4.2_04\jre\lib\ext. Now there is no log4j jar in the lib of the application I want to deploy. Thus now when i start my server there is no error.

Also I had to use these lines in the class calling the Logger.

import org.apache.log4j.*;
//***imp line to be included//**
org.apache.log4j.BasicConfigurator.configure();
//*************************//
Logger obj1 = null;
//***imp line to be included//**
System.setProperty("log4j.configuration","log4j.properties");
//*************************//
obj1 = Logger.getLogger(abc.class.getName());
//methods for outputing mesaages
obj1.debug("welcome");
obj1.info("welcome");
obj1.warn("welcome");
obj1.error("welcome");
obj1.fatal("welcome");

I hope it will solve out any issues that you all are facing.

Reagrds,
Roshani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4j\Layout error