aspose file tools*
The moose likes Java in General and the fly likes jar file prob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "jar file prob " Watch "jar file prob " New topic
Author

jar file prob

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
HI
what my application does is to connect to the database on a remote machine . When i converted that application into a jar file then the connection could not take place . What could be the reason .
yes and on more thing . i tried to run this jar file from the console and i got a run time exception saying that the drivers for the database had not loaded .
Do i need to include the jar file for the driver inside the jar which i,am creating cos i've already loaded the driver and set it in my classpath . Also this application works fine when run from console.
Please help me guys ... this is very urgent .
Thanks in advance
[ May 10, 2003: Message edited by: raghav mathur ]

Raghav.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Please help me guys ... this is really very urgent .
Thanks in advance
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
I tried my application to connect with MS acces . Its did!
I made a jar file of this applpication and tried . It did !
I tried the same thing with MySql database( on another ip). It did !
I made a jar file of this application and tried. IT DID NOT WORK !!!
It works with access . The application works with MySql too but when converted into a jar file ... it just refuses to connect .
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

When you make an executable JAR, I believe that the CLASSPATH system variable is ignored. As such, to include other .jar files/class paths, you have to specify in your manifest file the class path. Something like:
...
Class-Path: ./mysql.jar;./myclasses/
...
where everything is relative to the location that the executable jar is running from.
Connecting to Access workes because that uses Sun's JdbcOdbcDriver, which comes with the JRE. To get the MySQL driver to work, just include the path to the diriver in the manifest file as above.
[ May 12, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Joel
I've kept the drivers jar file in the same directory where the class file, the jar file and the source files are kept .
In that case what would be the classpath defination in the manifest file i will have to include.
Main-Class: Test
Classpath: .\mysql-connector-java-3.0.7-stable-bin.jar;
this is what i did ... didn't work
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Originally posted by raghav mathur:

Main-Class: Test
Classpath: .\mysql-connector-java-3.0.7-stable-bin.jar;

This is annoying part. The manifest entry should read:
Class-Path: .\mysql-connector-java-3.0.7-stable-bin.jar
Note the hyphen between Class and Path. I have no idea why they insist that the hyphen should be there, but it must be.
If this doesn't work, could you please paste the error you are getting and we'll take a closer look.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Also, not that it matters here, entries in the Class-path in the manifest are separated by spaces, not ; or :. Another annoying difference.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Originally posted by Joel McNary:
Also, not that it matters here, entries in the Class-path in the manifest are separated by spaces, not ; or :. Another annoying difference.

The exception arises on the statement where i try loading the driver( in my code) .
Afetr creating the manifest file i give the following command:
jar cvfm abc.jar manifest.mf *.class
Do i also need to include *.jar to include the drivers jar files ?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

No, you don't need to include it in the main .jar. Just reference it in the Class-Path attribute of the manifest file.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Originally posted by Joel McNary:
No, you don't need to include it in the main .jar. Just reference it in the Class-Path attribute of the manifest file.

That's exectly what i have been doing .... no success as yet . The drivers jar file have been refereenced in my own jars manifest the way i showed you in the above posts . What else do i need to include in the classpath variable of the manifest file?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Can you post a copy of you manifest file? Also, can you cut-and-paste a copy of the error message that you are getting?
Thanks.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Originally posted by Joel McNary:
Can you post a copy of you manifest file? Also, can you cut-and-paste a copy of the error message that you are getting?
Thanks.

Main-Class: Test
Class-Path: Drivers_jar_file
When i say java -jar test.jar... its says ... no class found(the drivers name) . The exception is thrown that no driver is found(which i have set in my code if the driver is not found)
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Does you manifest file literally say

Class-Path: Drivers_jar_file

?
For information about the Class-Path aspect of the manifest file, see this documentation.
Also, when you say that the exception is "no driver found" is this a ClassNotFound Exception when you say Class.forName(driverName)? Or are you getting some other error?
I just want to make sure that I'm working on your issue and not barking up the wrong tree here....
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Originally posted by Joel McNary:
Does you manifest file literally say

?
I just want to make sure that I'm working on your issue and not barking up the wrong tree here....


manifest file looks like this
Main-Class: Test
Classpath: mysql-connector-java-3.0.7-stable-bin.jar
the path inside the classpath is the drivers jar file which is in the same directory .
The error looks like this :
could not load JDBC driver: java.lang.ClassNotFoundException: orggjt.mm.mysql.Driver.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Thanks for the information:

Classpath: mysql-connector-java-3.0.7-stable-bin.jar

Again, this should read:
Class-Path: mysql-connector-java-3.0.7-stable-bin.jar
change your manifest file and try this again. Classpath: will not work; it must read "Class-Path:"
Hope that this helps.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
Thanks a ton joel
I will definately try this out. I would like you to know that i tried to extract all the class files from the driver's jar file and bundle them to my own jar file . IT WORKED !!!
I,am left with one more thing that is to bundle JRE wiht my aplication .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: jar file prob