Search code examples
javajdbcfirebirdjaybird

Jaybird java.lang.NoClassDefFoundError


Probably I'm asking a common question but I really don't get what I'm doing wrong and what I could forget when I try to connect with my Firebird DB through Jaybird. I've added the Jaybird.jar to my Java build path but still getting an error java.lang.NoClassDefFoundError.

Here is my simple code:

public class DBHelper {


    public void tryConnect() {
       try {
           Class.forName("org.firebirdsql.jdbc.FBDriver");
       } catch (ClassNotFoundException cnfe) {
           System.out.println(cnfe.toString());
           System.out.println("org.firebirdsql.jdbc.FBDriver not found");
       }
   }
}

Solution

  • Without the full exception message it is a guess, but you are likely receiving the error "java.lang.NoClassDefFoundError: javax/resource/ResourceException", which means you are missing the required dependency connector-api-1.5.jar (included in the lib-folder of the Jaybird distribution zip).

    You have two options:

    1. Add the connector-api-1.5.jar to the classpath, or
    2. Use jaybird-full-2.2.7.jar instead (it contains the classes from connector-api-1.5.jar).

    This is not necessary when deploying to an application server as that already provides the connector-api. You should only use jaybird-full-2.2.7.jar when running a standalone application; when deploying to an application server the presence of the classes in the javax.resource package might prevent the classloader from using your jar/war file.

    See also the Jaybird release notes, section Distribution package.

    Full disclosure: I am the developer of Jaybird