JAR Files with Class Paths

Discussion in 'Java' started by Jonathan, Dec 24, 2004.

  1. Jonathan

    Jonathan Guest

    Hello folks.

    I realize that problems with classpaths are a pretty common theme here,
    but I've been wrestling with this for days. I've been searching
    newsgroups and websites but I can't find an answer to my problem.

    I am trying to include the mysql JDBC driver with my application's JAR
    file. I've only succeeded to run the application with the driver by
    running the main class.

    I have tried to include the Class-Path with the JAR's manifest, like
    so:

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.2
    Created-By: 1.4.2_06-b03 (Sun Microsystems Inc.)
    Main-Class: Scheduler
    Class-Path: C:\physioclinic\mysql-connector-java-3.0.15-ga-bin.jar

    However, when I include the Class-Path attribute, the JAR can no longer
    find the Scheduler main class.

    I've experimented with including the build and dist directories in the
    Class-Path, but it will not find the main class when the Class-Path
    attribute is included.

    The only time it works is when I remove the Class-Path attribute. So
    I've tried including the jar for the driver on the command-line
    instead, running with

    java -classpath C:\physioclinic\mysql-connector-java-3.0.15-ga-bin.jar
    -jar dist\scheduler.jar

    Which runs, but cannot find the driver. It does find the driver when I
    do the same thing without the JAR file.

    Can anyone shed some light on this? Should I post my build file from
    ANT?

    I usually find my answers scouting the newsgroups but this time I can't
    seem to get anywhere. Thanks in advance. :(
     
    Jonathan, Dec 24, 2004
    #1
    1. Advertising

  2. Jonathan

    ByteCoder Guest

    Jonathan wrote:
    > Hello folks.
    >
    > I realize that problems with classpaths are a pretty common theme here,
    > but I've been wrestling with this for days. I've been searching
    > newsgroups and websites but I can't find an answer to my problem.
    >
    > I am trying to include the mysql JDBC driver with my application's JAR
    > file. I've only succeeded to run the application with the driver by
    > running the main class.
    >
    > I have tried to include the Class-Path with the JAR's manifest, like
    > so:
    >
    > Manifest-Version: 1.0
    > Ant-Version: Apache Ant 1.6.2
    > Created-By: 1.4.2_06-b03 (Sun Microsystems Inc.)
    > Main-Class: Scheduler
    > Class-Path: C:\physioclinic\mysql-connector-java-3.0.15-ga-bin.jar


    How about you put the mysql connector in the same directory as your jar
    file and run it with java -classpath . -jar Scheduler.jar

    --
    -------------
    - ByteCoder - ...I see stupid people
    -------------
    Curiosity *Skilled* the cat
     
    ByteCoder, Dec 24, 2004
    #2
    1. Advertising

  3. Jonathan

    Jonathan Guest

    Sure. It doesn't work--any ideas?

    C:\physioclinic\dist>java -classpath . -jar scheduler.jar

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    java.sql.SQLException: No suitable driver
    java.lang.NullPointerException

    C:\physioclinic\dist>dir
    Volume in drive C has no label.
    Volume Serial Number is D3C5-D3CD

    Directory of C:\physioclinic\dist

    12/24/2004 02:41 PM <DIR> .
    12/24/2004 02:41 PM <DIR> ..
    12/24/2004 03:22 PM 75,404 scheduler.jar
    09/04/2004 01:15 AM 235,712
    mysql-connector-java-3.0.15-ga-bin.jar
    2 File(s) 311,116 bytes
    2 Dir(s) 6,225,215,488 bytes free
    C:\physioclinic\dist>
     
    Jonathan, Dec 24, 2004
    #3
  4. Jonathan

    kjc Guest

    How about putting the jar with contains com.mysql.jdbc.Driver
    on out classpath

    Jonathan wrote:
    > Sure. It doesn't work--any ideas?
    >
    > C:\physioclinic\dist>java -classpath . -jar scheduler.jar
    >
    > java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    > java.sql.SQLException: No suitable driver
    > java.lang.NullPointerException
    >
    > C:\physioclinic\dist>dir
    > Volume in drive C has no label.
    > Volume Serial Number is D3C5-D3CD
    >
    > Directory of C:\physioclinic\dist
    >
    > 12/24/2004 02:41 PM <DIR> .
    > 12/24/2004 02:41 PM <DIR> ..
    > 12/24/2004 03:22 PM 75,404 scheduler.jar
    > 09/04/2004 01:15 AM 235,712
    > mysql-connector-java-3.0.15-ga-bin.jar
    > 2 File(s) 311,116 bytes
    > 2 Dir(s) 6,225,215,488 bytes free
    > C:\physioclinic\dist>
    >
     
    kjc, Dec 24, 2004
    #4
  5. Jonathan

    Jonathan Guest

    This doesn't seem to work?

    C:\physioclinic\dist>java -classpath
    mysql-connector-java-3.0.15-ga-bin.jar
    -jar scheduler.jar

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    java.sql.SQLException: No suitable driver
    java.lang.NullPointerException
     
    Jonathan, Dec 24, 2004
    #5
  6. Jonathan

    Jonathan Guest

    The command-line I posted didn't come out right. I had scheduler.jar
    at the end of that, and the program couldn't find com.mysql.jdbc.Driver
     
    Jonathan, Dec 24, 2004
    #6
  7. Jonathan

    kjc Guest

    where is mysql-connector-java-3.0.15-ga-bin.jar
    located. Absolute path.

    Jonathan wrote:
    > This doesn't seem to work?
    >
    > C:\physioclinic\dist>java -classpath
    > mysql-connector-java-3.0.15-ga-bin.jar
    > -jar scheduler.jar
    >
    > java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    > java.sql.SQLException: No suitable driver
    > java.lang.NullPointerException
    >
     
    kjc, Dec 24, 2004
    #7
  8. Jonathan

    Jonathan Guest

    I printed the directory listing in a previous post.

    C:\physioclinic\dist\mysql-connector-java-3.0.15-ga-bin.jar

    The absolute path used on the classpath didn't work either. It only
    works when I run from the class file.
     
    Jonathan, Dec 24, 2004
    #8
  9. Jonathan

    kjc Guest

    C:\physioclinic\dist>java -cp
    C:\physioclinic\dist\mysql-connector-java-3.0.15-ga-bin.jar
    -jar scheduler.jar


    kjc wrote:
    > where is mysql-connector-java-3.0.15-ga-bin.jar
    > located. Absolute path.
    >
    > Jonathan wrote:
    >
    >> This doesn't seem to work?
    >>
    >> C:\physioclinic\dist>java -classpath
    >> mysql-connector-java-3.0.15-ga-bin.jar
    >> -jar scheduler.jar
    >>
    >> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    >> java.sql.SQLException: No suitable driver
    >> java.lang.NullPointerException
    >>

    >
     
    kjc, Dec 24, 2004
    #9
  10. Jonathan

    Jonathan Guest

    This is what I was doing:

    C:\physioclinic\dist>java -cp
    C:\physioclinic\dist\mysql-connector-java-3.0.15-g
    a-bin.jar -jar scheduler.jar

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    java.sql.SQLException: No suitable driver
    java.lang.NullPointerException
    at DBConnection.query(DBConnection.java:49)
    at DayPanel.<init>(DayPanel.java:123)
    at MonthTable.mouseClicked(MonthTable.java:176)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown
    Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown
    Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at
    java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
    Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    C:\physioclinic\dist>
     
    Jonathan, Dec 24, 2004
    #10
  11. Jonathan

    kjc Guest

    The VM is not seeing your classpath for reasons i'm unaware of.
    Since i'm on a Linux platform, i've gone as far as I can.
    Any windows guys monitoring this thread.

    Jonathan wrote:
    > This is what I was doing:
    >
    > C:\physioclinic\dist>java -cp
    > C:\physioclinic\dist\mysql-connector-java-3.0.15-g
    > a-bin.jar -jar scheduler.jar
    >
    > java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    > java.sql.SQLException: No suitable driver
    > java.lang.NullPointerException
    > at DBConnection.query(DBConnection.java:49)
    > at DayPanel.<init>(DayPanel.java:123)
    > at MonthTable.mouseClicked(MonthTable.java:176)
    > at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    > at java.awt.Component.processMouseEvent(Unknown Source)
    > at java.awt.Component.processEvent(Unknown Source)
    > at java.awt.Container.processEvent(Unknown Source)
    > at java.awt.Component.dispatchEventImpl(Unknown Source)
    > at java.awt.Container.dispatchEventImpl(Unknown Source)
    > at java.awt.Component.dispatchEvent(Unknown Source)
    > at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown
    > Source)
    > at java.awt.LightweightDispatcher.processMouseEvent(Unknown
    > Source)
    > at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    > at java.awt.Container.dispatchEventImpl(Unknown Source)
    > at java.awt.Window.dispatchEventImpl(Unknown Source)
    > at java.awt.Component.dispatchEvent(Unknown Source)
    > at java.awt.EventQueue.dispatchEvent(Unknown Source)
    > at
    > java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    >
    > at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
    > Source)
    > at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    > at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    > at java.awt.EventDispatchThread.run(Unknown Source)
    > C:\physioclinic\dist>
    >
     
    kjc, Dec 24, 2004
    #11
  12. Jonathan

    Jonathan Guest

    Yeah, totally man. The only difference between linux and windows I'm
    aware of is the ; separator on the path as opposed to, I believe, the :
    I've included jars before and it's worked fine.
     
    Jonathan, Dec 24, 2004
    #12
  13. Jonathan

    ByteCoder Guest

    kjc wrote:
    > The VM is not seeing your classpath for reasons i'm unaware of.
    > Since i'm on a Linux platform, i've gone as far as I can.
    > Any windows guys monitoring this thread.
    >
    > Jonathan wrote:
    >
    >> This is what I was doing:
    >>
    >> C:\physioclinic\dist>java -cp
    >> C:\physioclinic\dist\mysql-connector-java-3.0.15-g
    >> a-bin.jar -jar scheduler.jar


    Yes. I had the same problem a while back. Back then I solved it by
    putting the driver in my own jar file.

    --
    -------------
    - ByteCoder - ...I see stupid people
    -------------
    Curiosity *Skilled* the cat
     
    ByteCoder, Dec 24, 2004
    #13
  14. kjc wrote:
    >
    > The VM is not seeing your classpath for reasons i'm unaware of.
    > Since i'm on a Linux platform, i've gone as far as I can.
    > Any windows guys monitoring this thread.
    >
    > Jonathan wrote:
    > > This is what I was doing:
    > >
    > > C:\physioclinic\dist>java -cp
    > > C:\physioclinic\dist\mysql-connector-java-3.0.15-g
    > > a-bin.jar -jar scheduler.jar
    > >
    > > java.lang.ClassNotFoundException: com.mysql.jdbc.Driver


    Sun's JVM ignores any classpath info when -jar is used. Just put everything in the
    classpath and don't use -jar.

    --
    Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Dec 24, 2004
    #14
  15. Jonathan

    Jonathan Guest

    You mean I should deploy my application as a bunch of class files..?
     
    Jonathan, Dec 25, 2004
    #15
  16. Jonathan wrote:
    >
    > You mean I should deploy my application as a bunch of class files..?


    If you mean putting all needed classes files in one jar, that is one solution. Another
    choice would be to use the classpath capabilities of the jar manifest file. I haven't
    used that solution, so check the docs to see if it will help.

    --
    Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Dec 25, 2004
    #16
  17. Jonathan

    Jonathan Guest

    Using the classpath of the jar manifest file was one of my original
    problems. Specifying the classpath within the manifest results in the
    jar being unable to find the main-class, even though it's specified in
    the manifest and included in the jar.
     
    Jonathan, Dec 25, 2004
    #17
  18. Jonathan

    Ann Guest

    "Jonathan" <> wrote in message
    news:...
    > Using the classpath of the jar manifest file was one of my original
    > problems. Specifying the classpath within the manifest results in the
    > jar being unable to find the main-class, even though it's specified in
    > the manifest and included in the jar.


    did you try relative path in your classpath or absolute path
    try the other one
     
    Ann, Dec 25, 2004
    #18
  19. Jonathan

    steve Guest

    On Sat, 25 Dec 2004 05:14:45 +0800, kjc wrote
    (in article <9F%yd.4605$>):

    > The VM is not seeing your classpath for reasons i'm unaware of.
    > Since i'm on a Linux platform, i've gone as far as I can.
    > Any windows guys monitoring this thread.
    >
    > Jonathan wrote:
    >> This is what I was doing:
    >>
    >> C:\physioclinic\dist>java -cp
    >> C:\physioclinic\dist\mysql-connector-java-3.0.15-g
    >> a-bin.jar -jar scheduler.jar
    >>
    >> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    >> java.sql.SQLException: No suitable driver
    >> java.lang.NullPointerException
    >> at DBConnection.query(DBConnection.java:49)
    >> at DayPanel.<init>(DayPanel.java:123)
    >> at MonthTable.mouseClicked(MonthTable.java:176)
    >> at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    >> at java.awt.Component.processMouseEvent(Unknown Source)
    >> at java.awt.Component.processEvent(Unknown Source)
    >> at java.awt.Container.processEvent(Unknown Source)
    >> at java.awt.Component.dispatchEventImpl(Unknown Source)
    >> at java.awt.Container.dispatchEventImpl(Unknown Source)
    >> at java.awt.Component.dispatchEvent(Unknown Source)
    >> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown
    >> Source)
    >> at java.awt.LightweightDispatcher.processMouseEvent(Unknown
    >> Source)
    >> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    >> at java.awt.Container.dispatchEventImpl(Unknown Source)
    >> at java.awt.Window.dispatchEventImpl(Unknown Source)
    >> at java.awt.Component.dispatchEvent(Unknown Source)
    >> at java.awt.EventQueue.dispatchEvent(Unknown Source)
    >> at
    >> java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    >>
    >> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
    >> Source)
    >> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    >> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    >> at java.awt.EventDispatchThread.run(Unknown Source)
    >> C:\physioclinic\dist>
    >>

    >


    you can read the system classpath from java.
    read the classpath. add the file the write it back out to the system
    classpath, actually in the program, then debug using this.
     
    steve, Dec 25, 2004
    #19
  20. Jonathan wrote:
    > I have tried to include the Class-Path with the JAR's manifest, like
    > so:
    >
    > Manifest-Version: 1.0
    > Ant-Version: Apache Ant 1.6.2
    > Created-By: 1.4.2_06-b03 (Sun Microsystems Inc.)
    > Main-Class: Scheduler
    > Class-Path: C:\physioclinic\mysql-connector-java-3.0.15-ga-bin.jar
    >
    > However, when I include the Class-Path attribute, the JAR can no longer
    > find the Scheduler main class.


    Did you verify that the manifest ends with a newline? Without it, the
    manifest isn't parsed correctly.

    --
    Regards,
    Remco.
     
    Remco Rotteveel, Dec 25, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cyril
    Replies:
    2
    Views:
    3,870
    cyril
    Aug 25, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    587
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,731
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,773
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    670
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page