java - Error loading SQLite file on Tomcat war app -
i trying use , embedded sqlite.db file on tomcat app. working on netbeans , deploying on local server through netbean's play button. far good. however, facing problem when build war file , deploy on raspberry pi tomcat. attach error below.
for som reason, same code works locally, won't work on tomcat server installed on raspberry. ideas?
thank you!
==== code ====
contextservice.java
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(); } }
sqlitemanager.java
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 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 30 sec. resultset rs = statement.executequery("select " + table_properties_columns.trip_number + " " + 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()); } { return tripnumber; } } }
sqlitetest.java
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(); } }
pom file
<?xml version="1.0" encoding="utf-8"?> <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"> <modelversion>4.0.0</modelversion> <groupid>com.app</groupid> <artifactid>sqlitetest</artifactid> <version>1.0</version> <packaging>war</packaging> <name>sqlitetest</name> <properties> <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>1.7.21</version> </dependency> <dependency> <groupid>ch.qos.logback</groupid> <artifactid>logback-classic</artifactid> <version>1.1.7</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency> <dependency> <groupid>org.xerial</groupid> <artifactid>sqlite-jdbc</artifactid> <version>3.8.11.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <compilerarguments> <endorseddirs>${endorsed.dir}</endorseddirs> </compilerarguments> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.3</version> <configuration> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <version>2.6</version> <executions> <execution> <phase>validate</phase> <goals> <goal>copy</goal> </goals> <configuration> <outputdirectory>${endorsed.dir}</outputdirectory> <silent>true</silent> <artifactitems> <artifactitem> <groupid>javax</groupid> <artifactid>javaee-endorsed-api</artifactid> <version>7.0</version> <type>jar</type> </artifactitem> </artifactitems> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
console output on netbeans local installation
== context initialized == 08:40:55.398 [http-nio-8080-exec-18] debug sqlitemanager - opened database 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
and error getting when build war file , deploy on raspberry through tomcat manager.
== 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 previous errors == context destroyed == aug 25, 2016 6:05:33 pm org.apache.catalina.loader.webappclassloaderbase clearreferencesjdbc warning: web application [/sqlitetest-1.0] registered jdbc driver [org.sqlite.jdbc] failed unregister when web application stopped. prevent memory leak, 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
java version on raspberry : openjdk version "1.8.0_40-internal" openjdk runtime environment (build 1.8.0_40-internal-b04) openjdk 0 vm (build 25.40-b08, interpreted mode)
tomcat version : apache tomcat/8.0.14 (debian) tomcat jvm 1.8.0_40-internal-b04
Comments
Post a Comment