Results 1 to 8 of 8
  1. #1
    MeathUltra is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default JDBC Driver errors in command line but not NetBeans

    Hello,

    I have a java application which I built with NetBeans 6.1 which connects to a MySql DB. When I run the application using F6 in NetBeans, everything runs correctly.

    However, when I run the application through the command line with this command:

    java -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"

    I get the following error:

    java.lang.noclassdeffounderror: com/mysql/jdbc/Connection

    I believe this is to do with a jar file minssing from the classpath. However, my classpath includes the location of the jar:

    .;C:\niall\Java\jdk1.6.0_02;C:\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga-bin.jar

    I have also tried to run the program on the command line with the following commands, both give the same werror as above:

    java -jar C:\path to my sql jar -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"

    Any help would be greatly appreciated.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Because you need to include the Driver jarfile on the classpath (use the -cp option). What you configure in NetBeans has no influence on what happens outside of NetBeans.

  3. #3
    MeathUltra is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default

    Hello Masijade, Thanks for you reply.

    Do You mean:

    java -jar C:\mysql-connector-java-5.0.7-bin.jar -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"

    ?

    I have tried this and the same error occurs.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    If you are going to use the -jar option, then you will have to configure the Classpath in the manifest file. What I said, was to use the -cp option.

    See
    Working with Manifest Files: The Basics (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
    and
    java - the Java application launcher

  5. #5
    MeathUltra is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default

    I have looked at these sites and havent found a lead to a solution in either.

    Any other ideas?

  6. #6
    w3user is offline Member
    Join Date
    Dec 2008
    Posts
    6
    Rep Power
    0

    Default

    option 1
    open command prompt
    java -cp C:\mysql-connector-java-5.0.7-bin.jar -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"

    option 2
    open command prompt
    set classpath=%classpath%;C:\mysql-connector-java-5.0.7-bin.jar
    java -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"

    option 3
    extract the RTN_Report_Manager.jar and open manifest.mf
    check the value of Main-Class
    open command prompt
    set classpath=%classpath%;C:\mysql-connector-java-5.0.7-bin.jar;C:\niall\RTN\dist\RTN_Report_Manager.jar
    java <Main-Class>

  7. #7
    MeathUltra is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default

    Hello W3User,

    Thanks for your help. I had already tried The first two options but had no luck. Using both returs the same java.lang error as stated in my first post.

    As for the third option, when tried, it
    doesnt work either. It advises that it cant find the main class.

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    With the -jar option both the system classpath and the -cp option is ignored. (as the second provided link explains) so you have to designate the classpath in the manifest file (as the first link explained). And using the -cp option means the System classpath with ignored. As you can see both option 1 and 2 above are completely invalid. And option 3, while peripherally correct, should have used the -cp option, rather than the system classpath, and should have spelled out that you need to reference your mainclass using the entire package path.

    Option 1 : set the classpath in the manifest file, and then
    Java Code:
    java -jar c:/full/path/to/your/jarfile.jar
    See the first link (and the second).

    Option 2:
    Java Code:
      java -cp C:/full/path/to/jdbc/driver.jar;C:/full/path/to/your/jarfile.jar full.package.path.YourMain
    Those are your options. You do not want to use the system classpath. As soon as you have more than one Java Application (both of which need their own and sometimes conflicting libraries) the system classpath quickly becomes a liability rather than an asset.

    You know, when you get a link to a resource, don't just skim it looking explicitly for a question and answer passage that exactly matches your problem. 99% of the time, that won't exist. Simply read (and attempt to comprehend) the entire document. Those two links explained everything you needed to know, if you would have just taken the time to actually read them.

Similar Threads

  1. Jdbc Driver For Oracle
    By Swamipsn in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 04:31 AM
  2. JDBC Driver problem
    By Swamipsn in forum New To Java
    Replies: 3
    Last Post: 08-09-2007, 03:55 PM
  3. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM
  4. Help with JDBC driver
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 07-03-2007, 08:16 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
  •