0

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");
       }
   }
}
whizzzkey
  • 926
  • 3
  • 21
  • 52
  • Kind of impossible to help with the information provided. Yes, it seems as if Jaybird.jar is either not in the classpath or does not contain FBDriver. Try to verify the latter manually. Does your IDE / build system confirm that the dependency is in the project? – Jan Groth Mar 20 '15 at 00:28
  • @jangroth " Does your IDE / build system confirm that the dependency is in the project? " - I use Eclipse Juno and in many my other projects all problems with build path solved by add .jar in Java build path in preferences. So maybe Jaybird.jar doesn't contain FBDriver? But I've downloaded it from firebird official site http://www.firebirdsql.org/en/jdbc-driver/ – whizzzkey Mar 20 '15 at 00:40
  • @jangroth How doy you think - is it can be a problem that I use JRE instead JDK? – whizzzkey Mar 20 '15 at 00:43
  • You can manually look into a JAR and confirm it's content. And I doubt that you don't use an JDK... :) – Jan Groth Mar 20 '15 at 01:06
  • Don't want to leave you alone with the problem, but it seems as if you might need to catch up on a few basics like how to handle dependencies. I would recommend using an IDE agnostic build system like maven to take care of that - but I guess with regards to your question I kind of out... – Jan Groth Mar 20 '15 at 01:09
  • Please post the entire stack trace. Likely you are missing the connector-1.5.jar required dependency. I'd be suspicious if you use jaybird.jar, because all releases in the past 10 years have had the version number included in the filename of the jar. See also http://www.firebirdsql.org/file/documentation/drivers_documentation/java/2.2.7/release_notes.html#__RefHeading__8761_1080388197 – Mark Rotteveel Mar 20 '15 at 06:19

1 Answers1

9

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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197