Given error:
INFO: Starting service Catalina Feb 15, 2016 2:23:09 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/8.0.23 Feb 15, 2016 2:23:09 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [116] milliseconds. Feb 15, 2016 2:23:09 PM org.apache.catalina.core.ContainerBase startInternal SEVERE: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/storyboard]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:917) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/storyboard]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 6 more Caused by: java.lang.NoClassDefFoundError: com/j256/ormlite/support/ConnectionSource at java.lang.Class.getDeclaredFields0(Native Method) at java.lang.Class.privateGetDeclaredFields(Class.java:2575) at java.lang.Class.getDeclaredFields(Class.java:1908) at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106) at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:256) at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:86) at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:63) at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:334) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:774) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5066) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 more Caused by: java.lang.ClassNotFoundException: com.j256.ormlite.support.ConnectionSource at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157) ... 20 more
Web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<servlet>
<servlet-name>UploadImage</servlet-name>
<servlet-class>com.home.storyboard.UploadServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>UploadCanvas</servlet-name>
<servlet-class>com.home.storyboard.UploadCanvas</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadImage</servlet-name>
<url-pattern>/uploadimage</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UploadCanvas</servlet-name>
<url-pattern>/uploadcanvas</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>StoryServlet</servlet-name>
<servlet-class>com.home.storyboard.StoryServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StoryServlet</servlet-name>
<url-pattern>/StoryServlet</url-pattern>
</servlet-mapping>
<listener>
<description>ServletContextListener</description>
<listener-class>com.home.storyboard.StartupListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
StartupListener
package com.home.storyboard;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
import java.sql.SQLException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.home.storyboard.DAOdb;
public class StartupListener implements ServletContextListener{
private final static String DATABASE_URL = "jdbc:sqlite:testdb.db";
ConnectionSource connectionSource = null;
@Override
public void contextInitialized(ServletContextEvent sce) {
try {
// create our data-source for the database
connectionSource = new JdbcConnectionSource(DATABASE_URL);
DAOdb db = new DAOdb(connectionSource);
sce.getServletContext().setAttribute("db", db);
}catch(SQLException e){
System.out.println(e.getMessage());
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// destroy the data source which should close underlying connections
DAOdb db = (DAOdb)sce.getServletContext().getAttribute("db");
db.close();
}
}
DAOdb class
package com.home.storyboard;
import java.sql.SQLException;
import java.util.List;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.table.TableUtils;
import com.j256.ormlite.support.ConnectionSource;
public class DAOdb {
// we are using the in-memory H2 database
private final ConnectionSource connectionSource;
private Dao<User, Integer> userDAO;
private Dao<Profile,Integer> profileDAO;
private Dao<Story, Integer> storyDAO;
private String lastError;
public DAOdb(ConnectionSource connectionSource){
this.connectionSource=connectionSource;
try{
userDAO = DaoManager.createDao(connectionSource, User.class);
TableUtils.createTable(connectionSource, User.class);
profileDAO = DaoManager.createDao(connectionSource, Profile.class);
TableUtils.createTable(connectionSource, Profile.class);
storyDAO = DaoManager.createDao(connectionSource, Story.class);
TableUtils.createTable(connectionSource, Story.class);
}catch(SQLException e){
lastError = e.getMessage().toString();
}
}
/**
* DAO Functions to fetch data
*/
public void addStory(Story S) {
try{
storyDAO.create(S);
lastError = null;
} catch (Exception e) {
lastError = e.getMessage().toString();
}
}
public List<Story> getStoriesbyUsername(String username) {
String uname =username;
List<Story> storyList = null;
User user = getUserbyUsername(uname);
Integer uid =user.getId();
try{
GenericRawResults<String[]> stories = storyDAO.queryRaw(
"select count(*) from stories where userid = uid");
// there should be 1 result
List<String[]> results = stories.getResults();
// the results array should have 1 value
Integer usercount = results.size();
// this should print the number of orders that have this account-id
if(usercount<=0){
lastError="'No story exists by username'+' '+ username";
}else{
storyList = storyDAO.queryBuilder()
.where()
.eq(Story.USERID_FIELD_NAME, uid)
.query();
}
}catch(SQLException e){
lastError = e.getMessage().toString();
}
return storyList;
}
}