• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

jar file prob

 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me guys ... this is really very urgent .
Thanks in advance
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic