Menu

Library Conflict: java.lang.NoClassDefFoundError

Help
2016-12-16
2016-12-17
  • Michel Leong

    Michel Leong - 2016-12-16

    Greetings.

    I recently had to migrate a project to start using UCanAccess library. At this point, I am having some issues with library conflicts and would like to request some help on the best way to solve it.

    The error I'm getting is

    Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class net.ucanaccess.jdbc.UcanaccessDriv
    er
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at java.sql.DriverManager.isDriverAllowed(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at database.SQLConnector.dbConnect(SQLConnector.java:72)
            at database.SQLConnector.establishConnection(SQLConnector.java:86)
            at main.Launcher.run(Launcher.java:67)
            at main.Launcher.main(Launcher.java:285)
    

    The error in my code is triggered in the following method, which is establishing a connection to a MySQL database, but for some reason tries to use UCanAccess.

    import java.sql.DriverManager
    ...
    private Connection dbConnect(String db_connect_string, String db_userid,
                String db_password) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
    
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection conn = DriverManager.getConnection(db_connect_string+
                    db_userid+db_password);
    
                return conn;
        }
    

    I am placing UCanAccess jar and its dependency libraries in the "lib/ext" of my JRE folder.

    I am using JRE8_101.

    Please let me know what is the best way to avoid this library conflict.

    If further information is needed, please let me know.

    Thanks and best regards.

     
  • Gord Thompson

    Gord Thompson - 2016-12-16

    Try commenting out the Class.forName statement to see if that makes any difference. (It may not even be necessary.)

     
  • Michel Leong

    Michel Leong - 2016-12-17

    Hi again,

    I solved my problem by removing all the jar files in my library and adding back one by one according to the need of my projects.

    After doing this, the problem no longer occurred.

    Thanks again.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.