JAR Files with Class Paths

J

Jonathan

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. :(
 
B

ByteCoder

Jonathan said:
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
 
J

Jonathan

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>
 
J

Jonathan

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
 
J

Jonathan

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
 
J

Jonathan

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.
 
K

kjc

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

Jonathan

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>
 
K

kjc

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.
 
J

Jonathan

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.
 
B

ByteCoder

kjc said:
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.

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

Lee Fesperman

kjc said:
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.

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

Lee Fesperman

Jonathan said:
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.
 
J

Jonathan

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.
 
A

Ann

Jonathan said:
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
 
S

steve

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.

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.
 
R

Remco Rotteveel

Jonathan said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top