CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2010
    Posts
    121

    class not found exception com.mysql.jdbc.driver jar

    I am working on a java front-end with a mysql database back-end.
    It work's well in Eclipse, however, when I export it to a jar file I get the following 'class not found exception com.mysql.jdbc.driver jar' error via command prompt (see screenshot)

    Maybe it's my main class? I know it has something to do with the build path but everything looks ok to me?

    Code:
    	public static void main(String[] args) {
    		 try {
    			Class.forName(JDBC_DRIVER);
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		new DatabaseView();
    
    	}
    Attached Images Attached Images

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: class not found exception com.mysql.jdbc.driver jar

    Have you included the mysql driver jar on the classpath when starting the app (or better still have you added a class-path line in your manifest file that includes the mysql driver jar).
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Feb 2010
    Posts
    121

    Re: class not found exception com.mysql.jdbc.driver jar

    Hi,

    The mysql driver is on the build path (as far as I can tell). I added it by right-clicking on the project in Eclipse/build path/configure and under Libraries I can see the mysql driver which I have under my lib folder. My program runs fine in Eclipse, i.e. my JFrame boots up etc and I can connect to the the mysql database.

    Here is my manifest file

    Code:
    Manifest-Version: 1.0
    Main-Class: GrantsDB.DatabaseView
    Class-Path: lib.mysql-connector-java-5.1.18-bin.jar
    (There is a blank line at the last line)

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: class not found exception com.mysql.jdbc.driver jar

    The class-path line should be:
    Code:
    Class-Path: lib/mysql-connector-java-5.1.18-bin.jar
    and the jar must be in a directory called lib which must be in the directory containing your program jar file.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Feb 2010
    Posts
    121

    Re: class not found exception com.mysql.jdbc.driver jar

    Thanks - hadn't noticed that 'forward slash'.
    Still can't create my jar file. 2 more screenshots 1)my layout in Eclipse and 2) the latest output from command
    Attached Images Attached Images

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: class not found exception com.mysql.jdbc.driver jar

    Still can't create my jar file.
    What do you mean you can't create your jar file, I thought you said it wouldn't run.

    Assuming you meant you can't run it, where is the jar on your hard drive relative to the lib directory?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    Feb 2010
    Posts
    121

    Re: class not found exception com.mysql.jdbc.driver jar

    Apologies, I meant run jar not create.
    Anyway, thanks for the lead - I put the jar in the folder relative to the lib directory and it is now running :-)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured