Error loading SQLite file on Tomcat war app
<p>I am trying to use and embedded sqlite.db file on my tomcat app. I am working on NetBeans and deploying it on a local server through Netbean's play button. so far so good. However, I am facing a problem when I build a war file and deploy it on a Raspberry PI tomcat. I attach the error below.</p>

<p>For som reason, the same code that works locally, won't work on this tomcat server installed on Raspberry. Any ideas?</p>

<p>Thank you!</p>

<p>==== CODE ====</p>

<p>ContextService.java</p>

<pre><code>public class ContexService implements ServletContextListener {


    /**
     * 
     * @param sce 
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {

        System.out.println("== context initialized ==");
        SqliteTest.getInstance().start();
        SqliteTest.getInstance().stop();

    }

    /**
     * 
     * @param sce 
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {

        System.out.println("== context destroyed ==");
        SqliteTest.getInstance().stop();
    }

}
</code></pre>

<p>SQLiteManager.java</p>

<pre><code>public class SQLiteManager {

    private static final Logger logger = LoggerFactory.getLogger(SQLiteManager.class);
    private static SQLiteManager instance = null;
    private static Connection connection = null;

    private static int QUERY_TIMEOUT = 5;
    private static String TABLE_PROPERTIES = "Properties";
    private static String DB_NAME = "safemo.db";

    private static class TABLE_PROPERTIES_COLUMNS {

        public static final String TRIP_NUMBER = "tripNumber";
    }

    private SQLiteManager() {
        openDB();
    }

    public static SQLiteManager getInstance() {
        if (instance == null) {
            instance = new SQLiteManager();
        }

        return instance;

    }

    private void openDB() {
        if (connection == null) {
               connect();
        } else {
            try {
                if (connection.isClosed()) {
                    connect();
                }
            } catch (SQLException ex) {
                logger.error("Error openning connection : " + ex.getMessage());
            }
        }
    }

    private void connect() {

        try {
            Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite::resource:" + DB_NAME);

            logger.debug("Opened database successfully");
        } catch (ClassNotFoundException ex) {
            logger.error(ex.getMessage());
        } catch (SQLException ex) {
            logger.error(ex.getMessage());
        }

    }

    public void closeDB() {
        try {
            if (connection != null) {
                connection.close();
            }
            logger.debug("Connection closed successfully");
        } catch (SQLException ex) {
            logger.error("Error closing database : " + ex.getMessage());
        }
    }

    public void incrementTripNumber()
    {
         try {
            Statement statement = connection.createStatement();
            statement.setQueryTimeout(QUERY_TIMEOUT);  // set timeout to 30 sec.
            statement.executeUpdate("UPDATE " + TABLE_PROPERTIES + " SET " + TABLE_PROPERTIES_COLUMNS.TRIP_NUMBER + " = " + TABLE_PROPERTIES_COLUMNS.TRIP_NUMBER + " + 1");
        } catch (SQLException ex) {
            logger.error("Error getting trip number : " + ex.getMessage());
        }

    }

    public int getTripNumber() {

        int tripNumber = -1;

        try {
            Statement statement = connection.createStatement();
            statement.setQueryTimeout(QUERY_TIMEOUT);  // set timeout to 30 sec.
            ResultSet rs = statement.executeQuery("SELECT " + TABLE_PROPERTIES_COLUMNS.TRIP_NUMBER + " FROM " + TABLE_PROPERTIES);

            if (rs.next()) {
                tripNumber = rs.getInt(TABLE_PROPERTIES_COLUMNS.TRIP_NUMBER);
            }

            rs.close();

        } catch (SQLException ex) {
            logger.error("Error getting trip number : " + ex.getMessage());
        } finally {
            return tripNumber;
        }
    }
}
</code></pre>

<p>SQLiteTest.java</p>

<pre><code>public class SqliteTest 
{
    private static SqliteTest instance = null;
     private static final Logger logger = LoggerFactory.getLogger(SqliteTest.class);

    private SqliteTest()
    {

    }

    public static SqliteTest getInstance()
    {
        if(instance == null)
        {
            instance = new SqliteTest();
        }

         return instance;

    }

    public void start()
    {
        SQLiteManager sqliteManager = SQLiteManager.getInstance();
        logger.debug("TRIP NUMBER : " + sqliteManager.getTripNumber());
        sqliteManager.incrementTripNumber();
        logger.debug("TRIP NUMBER INCREASED: " + sqliteManager.getTripNumber());

    }

    public void stop()
    {
        SQLiteManager.getInstance().closeDB();
    }
}
</code></pre>

<p>Pom File</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;com.app&lt;/groupId&gt;
    &lt;artifactId&gt;SqliteTest&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;

    &lt;name&gt;SqliteTest&lt;/name&gt;

    &lt;properties&gt;
        &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    &lt;/properties&gt;

    &lt;dependencies&gt;

         &lt;dependency&gt;
            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
            &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
            &lt;version&gt;1.7.21&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
            &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
            &lt;version&gt;1.1.7&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;javax&lt;/groupId&gt;
            &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
            &lt;version&gt;7.0&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;

          &lt;dependency&gt;
            &lt;groupId&gt;org.xerial&lt;/groupId&gt;
            &lt;artifactId&gt;sqlite-jdbc&lt;/artifactId&gt;
            &lt;version&gt;3.8.11.2&lt;/version&gt;
        &lt;/dependency&gt;

    &lt;/dependencies&gt;

    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.1&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;source&gt;1.7&lt;/source&gt;
                    &lt;target&gt;1.7&lt;/target&gt;
                    &lt;compilerArguments&gt;
                        &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                    &lt;/compilerArguments&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                &lt;version&gt;2.3&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                &lt;version&gt;2.6&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;phase&gt;validate&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;copy&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                            &lt;silent&gt;true&lt;/silent&gt;
                            &lt;artifactItems&gt;
                                &lt;artifactItem&gt;
                                    &lt;groupId&gt;javax&lt;/groupId&gt;
                                    &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                    &lt;version&gt;7.0&lt;/version&gt;
                                    &lt;type&gt;jar&lt;/type&gt;
                                &lt;/artifactItem&gt;
                            &lt;/artifactItems&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

&lt;/project&gt;
</code></pre>

<p>console output on Netbeans local installation</p>

<pre><code>== context initialized ==
08:40:55.398 [http-nio-8080-exec-18] DEBUG SQLiteManager - Opened database successfully
08:40:55.406 [http-nio-8080-exec-18] DEBUG SqliteTest - TRIP NUMBER : 2
08:40:55.543 [http-nio-8080-exec-18] DEBUG SqliteTest - TRIP NUMBER INCREASED: 3
08:40:55.543 [http-nio-8080-exec-18] DEBUG SQLiteManager - Connection closed successfully 
</code></pre>

<p>And this is the error I am getting when I build the war file and deploy it on Raspberry through Tomcat manager.</p>

<pre><code>== context initialized ==
Aug 25, 2016 6:05:33 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Aug 25, 2016 6:05:33 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/SqliteTest-1.0] startup failed due to previous errors
== context destroyed ==
Aug 25, 2016 6:05:33 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [/SqliteTest-1.0] registered the JDBC driver [org.sqlite.JDBC] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Aug 25, 2016 6:05:33 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/tomcat8/webapps/SqliteTest-1.0.war has finished in 42,719 ms
</code></pre>

<p>java version on Raspberry : 
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b04)
OpenJDK Zero VM (build 25.40-b08, interpreted mode)</p>

<p>Tomcat version : Apache Tomcat/8.0.14 (Debian)
Tomcat JVM 1.8.0_40-internal-b04</p>