I am trying to build a single jar file for my project with all other libraries included (database drivers, etc). The build process works fine and I am able to create the jar. I am using Netbeans IDE for the same.
My problem:
When I run the jar file directly by double clicking it in windows 7 or Ubuntu, jdbc (sqlite) driver doesn't work. Although when I run it from command line using
java -jar myproject.jar
, it works fine. Also it is working fine in Windows 8 and Mac OS by double clicking.
Here's the portion of build.xml that I use for making a single jar:
<target name="-post-jar">
<property name="store.jar.name" value="myproject"/>
<property name="store.dir" value="dist"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
Also interestingly, all other libraries (like jcalender) that I've used work well, except sqlite-jdbc. Any thoughts on why this may be happening?
Note : I also don't get any exceptions, ClassNotFoundException or such.
Edits :
When I use a print statement (by which I mean writing to a file) before and after the jdbc connection statement, nothing happens in win 7/ubuntu.
I tried using the same version of jre as that of Mac OS and Win 8 (i.e. jre 1.8) on ubuntu, thinking that maybe that was causing some problems. But nope, no luck there.
My database connection code :
Class.forName("org.sqlite.JDBC");
SQLiteConfig config = new SQLiteConfig();
config.enforceForeignKeys(true);
System.out.println(config.toProperties());
ErrorLog.write_to_file("fetching connection");
Connection conn = DriverManager.getConnection("jdbc:sqlite:Data.db",config.toProperties());
Statement stmt=conn.createStatement();
ErrorLog.write_to_file("connected");
The ErrorLog class writes errors to a file. Also please note that this portion is in a try-catch block. In the catch block, I again use ErrorLog to write to file
I've put the database file in the same folder as the jar file.