Results 1 to 10 of 10
  1. #1
    jte
    jte is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default ClassNotFoundException from jar file

    I have developed a programm that connects to a Firebird database.

    I use Eclipse as a development environment.
    Executing the programm in Eclipse it works ok.

    When I make an executable jar file it gives a ClassNotFoundException caused by the "Class.forName(DBConst.DRIVERNAAM);" statement.

    Below some details from the code.

    What am i missing?

    Java Code:
    private void maakVerbinding() throws DatabaseException {
        try {
          //DriverManager.setLogWriter(new PrintWriter(System.out));
          Class.forName(DBConst.DRIVERNAAM);
          con = DriverManager.getConnection(DBConst.URL, DBConst.GEBRUIKERSNAAM, 
                                            DBConst.WACHTWOORD);
        }
        catch (ClassNotFoundException e) {
          throw new DatabaseException("De klasse voor het laden van de driver kan niet gevonden worden");
        } 
        
        catch (SQLException e) {
          throw new DatabaseException("Er kan geen verbinding met de database worden gemaakt");
        }
      }
    Last edited by JosAH; 04-26-2012 at 04:54 PM. Reason: added [code] ... [/code] tags.

  2. #2
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: ClassNotFoundException from jar file

    Please put [code][/code] tags around your Java code.

  3. #3
    jte
    jte is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: ClassNotFoundException from jar file

    Ok, I will do that next time.

  4. #4
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: ClassNotFoundException from jar file

    There's no time like the present! Please edit that post and add them.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: ClassNotFoundException from jar file

    Quote Originally Posted by jte View Post
    Ok, I will do that next time.
    I fixed the tags for you in your original post; most likely your program can't find the class 'DRIVERNAME'; check your classpath.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: ClassNotFoundException from jar file

    In your catch blocks either log the original exception (e.printStackTrace()) or attach it to the new exception.
    You are losing a ton of useful information about where and what exact exception is being thrown (like what class is not being found).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    jte
    jte is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: ClassNotFoundException from jar file

    Thank you for fixing the tags, next time I know how to do it.

    Ok, so I'm missing "org.firebirdsql.jdbc.FBDriver" in my classpath.
    I checked the jar file content with the jar statement and the class mentioned above is indeed missing.

    I'm new to Java but I understand the basics from the jar command and manifest files.
    So maybe my next question is stupid.

    Leaves me with the problem where do I find the jar file that contains the class "org.firebirdsql.jdbc.FBDriver".
    I looked on my C drive and can't find a jar file that rings a bell.

    How do I know which jar file it is and how does Eclipse knows it?
    There the programm runs without a problem.

  8. #8
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: ClassNotFoundException from jar file

    You must have the Firebird Eclipse plugin installed and your project's build path has been setup to have Firebird included. I would suggest you visit the Firebird homepage and look for their documentation. Having the Eclipse plugin may not be sufficient for you to run your application outside of Eclipse. There may be Firebird runtime you have to install and include in your classpath. That should all be in their documentation.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: ClassNotFoundException from jar file

    I've not used Firebird, but presuming it's a standalone database, then you should have a jdbc driver jar for it somewhere.
    That should be all you need to have on your runtime classpath (note, classpath, not CLASSPATH).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    jte
    jte is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: ClassNotFoundException from jar file

    I was looking further around on my C drive and I found the driver class in a directory "..\Java\jdk1.6.0_04\jre\lib\ext\Driver Firebird\org\firebirdsql\jdbc" with the name "FBDriver.class".

    Also on the Firebird website I found the jdbc driver.

    One option is that I download the driver and with a manifest file add it to my jar command.
    Is that the way to do it or are there other and easier options?

Similar Threads

  1. ClassNotFoundException!! Oh BOY!!
    By Joel in forum New To Java
    Replies: 13
    Last Post: 08-26-2011, 09:47 AM
  2. ClassNotFoundException...
    By providence in forum JDBC
    Replies: 2
    Last Post: 02-02-2011, 06:45 PM
  3. Replies: 4
    Last Post: 12-30-2010, 01:23 PM
  4. ClassNotFoundException
    By meprasobh in forum New To Java
    Replies: 2
    Last Post: 10-17-2010, 03:32 PM
  5. ClassNotFoundException
    By oontvoo in forum Java Applets
    Replies: 7
    Last Post: 05-13-2010, 11:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •