Exception in thread "main" java.lang.NoClassDefFoundError: org / sqlite / NativeDB

I am trying to run a simple example for sqlite on mac. I am sure the code works well on Windows. But not on mac. I really appreciate this if someone can help me with this.

The code works in Eclipse. I added sqlite-jdbc4-3.8.2-SNAPSHOT.jar as the internal and external jar in the project.

public class Test1 { private static Connection c; private static String filepath = "/Users/zerocraft/Documents/workspace/sql_test/"; private static String sql; private static Statement query; public static void main(String[] args) { System.out.println("START"); try{ Class.forName("org.sqlite.JDBC"); System.out.println("START2"); c = DriverManager.getConnection("jdbc:sqlite:"+filepath+"projone.db"); System.out.println("START3"); } catch(Exception e){ e.printStackTrace(); } sql = "INSERT INTO table(date,time,client_id,run_id,latitude," + "longitude,bearing,speed,altitude,sensor_id,sensor_type," + "sensor_value,attribute)" + "VALUES ('A','B','C','D',0,1,2,3,4,'E','F','G','H')"; try{ query = c.createStatement(); query.executeUpdate(sql); query.close(); } catch(SQLException el){el.printStackTrace();} } } 

Console ##

  START START2 Exception in thread "main" java.lang.NoClassDefFoundError: org/sqlite/NativeDB at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851) at java.lang.Runtime.load0(Runtime.java:795) at java.lang.System.load(System.java:1062) at org.sqlite.SQLiteJDBCLoader.loadNativeLibrary(SQLiteJDBCLoader.java:200) at org.sqlite.SQLiteJDBCLoader.extractAndLoadLibraryFile(SQLiteJDBCLoader.java:148) at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:249) at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:65) at org.sqlite.core.NativeDB.load(NativeDB.java:53) at org.sqlite.core.CoreConnection.open(CoreConnection.java:136) at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:66) at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:21) at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23) at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:44) at org.sqlite.JDBC.createConnection(JDBC.java:113) at org.sqlite.JDBC.connect(JDBC.java:87) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:233) at sql_test.Test1.main(Test1.java:22) Caused by: java.lang.ClassNotFoundException: org.sqlite.NativeDB at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 21 more 
+6
source share
3 answers

Finally, I figured out how to make it work. I tried another jar and it (sqlite-jdbc-3.7.2.jar) works fine for Mac. It seems that sqlite-jdbc4-3.8.2-SNAPSHOT.jar. @ddevienne, possibly 3.8.2 does not support Mac OS.

+13
source

This is a bug in version 3.8.2-SNAPSHOT: http://bitbucket.org/xerial/sqlite-jdbc/issue/127
Native libraries are present for Linux, Mac, and Windows, but only windows alone use the correct package of the NativeDB class.

+6
source

If you carefully read the stack trace, you will see that SQLiteJDBCLoader was successfully found and loaded, then it ran extractAndLoadLibraryFile to load its own dynamic SQLite library. But loading this native lib failed. This means that the jar has a native lib built in, which, unlike Java byte code, is platform independent. Thus, either he implements a native lib for several OSs, or one OS such as Windows, explaining why your bank works in Windows, and not in MAC OS.

+1
source

All Articles