aspose file tools*
The moose likes Struts and the fly likes SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown" Watch "SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown" New topic
Author

SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown

D. Deepak Sharma
Ranch Hand

Joined: May 12, 2012
Posts: 31
Hello everyone I am Deepak Sharma, I am novice to Struts and Hibernate. I was trying to integrate Struts 1.3.10 and Hibernate 3.6.10final Dist. and I am getting this error as I start the Server.
FULL CONSOLE IS LIKE THIS
Jun 27, 2012 3:35:19 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.7.0_01\bin;.
Jun 27, 2012 3:35:19 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsExample1' did not find a matching property.
Jun 27, 2012 3:35:19 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:RegistrationForm' did not find a matching property.
Jun 27, 2012 3:35:20 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 27, 2012 3:35:20 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1111 ms
Jun 27, 2012 3:35:20 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 27, 2012 3:35:20 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Jun 27, 2012 3:35:21 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/D:/WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RegistrationForm/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
Jun 27, 2012 3:35:21 PM org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
INFO: Tiles definition factory loaded for module ''.
Jun 27, 2012 3:35:21 PM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable. Most likely, this is due to an incorrect or missing library dependency.
java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:172)
at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:147)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:842)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:359)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
... 27 more

Jun 27, 2012 3:35:21 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet action as unavailable
Jun 27, 2012 3:35:21 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /RegistrationForm threw load() exception
javax.servlet.UnavailableException: org/hibernate/HibernateException
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Jun 27, 2012 3:35:22 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/D:/WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsExample1/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
Jun 27, 2012 3:35:22 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 27, 2012 3:35:22 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 27, 2012 3:35:22 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/78 config=null
Jun 27, 2012 3:35:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2760 ms

I have created HibernatePlugin.java, Tutorial.java as Bean class, hibernate.cfg.xml, Tutorial.hbm.xml for mapping and I am attaching the code files along with the post
CODE FOR HIBERNATEPLUGIN is
package com.deepak.sh;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;


public class HibernatePlugin implements PlugIn {
private String _configFilePath = "/hibernate.cfg.xml";

/**
* the key under which the <code>SessionFactory </code> instance is stored
* in the <code>ServletContext</code>.
*/
public static final String SESSION_FACTORY_KEY = SessionFactory.class.getName();

private SessionFactory _factory = null;

public void destroy() {
try{
_factory.close();
}catch(HibernateException e){
System.out.println("Unable to close Hibernate Session Factory: " + e.getMessage());
}

}

public void init(ActionServlet servlet,
ModuleConfig config) throws ServletException {
System.out.println("*************************************");
System.out.println("**** Initilizing HibernatePlugIn **********");
Configuration configuration = null;
URL configFileURL = null;
ServletContext context = null;

try{
configFileURL =
HibernatePlugin.class.getResource(_configFilePath);
context = servlet.getServletContext();
configuration = (new Configuration()).configure(configFileURL);
_factory = configuration.buildSessionFactory();
//Set the factory into session
context.setAttribute(SESSION_FACTORY_KEY, _factory);

}catch(HibernateException e){
System.out.println("Error while initializing hibernate: " + e.getMessage());
}
System.out.println("**************** *********************");

}

/**
* Setter for property configFilePath.
* @param configFilePath New value of property configFilePath.
*/
public void setConfigFilePath(String configFilePath) {
if ((configFilePath == null) || (configFilePath.trim().length() == 0)) {
throw new IllegalArgumentException("configFilePath cannot be blank or null.");
}

System.out.println("Setting ' configFilePath' to '" + configFilePath + "'...");
_configFilePath = configFilePath;
}


/*(SessionFactory) servletContext.getAttribute
(HibernatePlugIn.SESSION_FACTORY_KEY);
*/

}

CODE FOR TUTORIAL.JAVA IS
package com.deepak.sh;

import java.io.Serializable;

public class Tutorial implements Serializable {

/**
*
*/
private static final long serialVersionUID = -7405919684626234375L;

private Integer id;
private String shortdesc;
private String longdesc;
private String url;
public Tutorial(Integer id, String shortdesc, String longdesc, String url){
this.id=id;
this.shortdesc=shortdesc;
this.longdesc=longdesc;
this.url=url;
}
public Tutorial(){}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getShortdesc() {
return shortdesc;
}
public void setShortdesc(String shortdesc) {
this.shortdesc = shortdesc;
}
public String getLongdesc() {
return longdesc;
}
public void setLongdesc(String longdesc) {
this.longdesc = longdesc;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}


}

TUTORIAL.HBM.XML
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 27, 2012 3:20:08 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.deepak.sh.Tutorial" table="TUTORIAL">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="increment" />
</id>
<property name="shortdesc" type="java.lang.String" not-null="true" length="50">
<column name="SHORTDESC" />
</property>
<property name="longdesc" type="java.lang.String" not-null="true" length="250">
<column name="LONGDESC" />
</property>
<property name="url" type="java.lang.String" not-null="true" length="100">
<column name="URL" />
</property>
</class>
</hibernate-mapping>

Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

Welcome to the Ranch!
Jun 27, 2012 3:35:21 PM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable. Most likely, this is due to an incorrect or missing library dependency.
java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)

you don't have hibernate-xxx.jar on the classpath.
try putting it in server/lib or in the CLASSPATH defined in the server's run command.


Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
D. Deepak Sharma
Ranch Hand

Joined: May 12, 2012
Posts: 31
Jun 27, 2012 3:35:21 PM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable. Most likely, this is due to an incorrect or missing library dependency.
java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)

you don't have hibernate-xxx.jar on the classpath.
try putting it in server/lib or in the CLASSPATH defined in the server's run command.

Yes its working mam thanks I closed the IDE then it worked as you said. THANKS A LOT.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown
 
Similar Threads
Getting Exception while executing hibernate plugin
Cannot find bean: "Element" in any scope
SQLGrammarException
SEVERE: Duplicate entry '1' for key 'PRIMARY'
DATABASE ERROR: java.sql.SQLException: Invalid argument(s) in call