Jdbc driver not found when putting an application in a jar-file
Terence Gronowski
Ranch Hand
Joined: Dec 19, 2007
Posts: 64
posted
0
I want to pack my application in a .jar file.
I run an application which needs sqljdbc4.jar to access a Sql 2008 Express server. Without the jar the application runs well and gets access to the database. With the jar file it doesn't.
I wrap as follows:
Make Manifest.txt with the following contents: Main-Class: MyMainClass (plus empty line)
Make executable jar: jar -cfm MyAppl.jar Manifest.txt *.class
it seems your sqljdbc4.jar is not accessible when you run your application. Since you can't specify additional jars to the class path when using -jar, I would suggest to go with
java -cp MyAppl.jar;sqljdbc4.jar MyMainClass
Tamas
Terence Gronowski
Ranch Hand
Joined: Dec 19, 2007
Posts: 64
posted
0
Thanks for the tip, Tamas
I just want one file to cklick on. When I have the application in a .class file, it works well (I have sqljdbc4.jar in the classpath). I do not understand, if I have the folder wrapped in a .jar file, sqljdbc4.jar is not found any more.
If you really want just a single jar file, then you need to package the classes that make up the JDBC driver along with your application classes (adding the driver jar file as it is to your app's jar file will not work).
Don't forget to end with a newline. The important thing is "Class-Path: sqljdbc4.jar", showing where the driver is.
I copied sqljdbc4.jar in the same folder as the program.
Creating a jar of the program folder:
jar cfm pp.jar Manifest.txt *.*
With *.* I include alle files, the sqljdbc4.jar, too. When I delete sqljdbc4.jar the pp.jar works well nevertehless, I suppose that sqljdbc4.jar is found in pp.jar.
I still have it in the Classpath elsewhere. But I thought it would use the sqljdbc4.jar in the pp.jar folder. If this is not the case I do not understand that one must have
Class-Path: sqljdbc4.jar
in the Manifest.txt file.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35250
7
posted
0
I still have it in the Classpath elsewhere.
What makes you say that? What *is* the classpath - do you have a CLASSPATH environment variable? If so, I advise to remove it and never to use it again; it causes more problems than it solves.
But I thought it would use the sqljdbc4.jar in the pp.jar folder.
It will. If you double-click a jar file then the classpath consists of the jar file and whatever else is listed in its manifest.
Terence Gronowski
Ranch Hand
Joined: Dec 19, 2007
Posts: 64
posted
0
Ulf, many thanks
sqljdbc4.jar is found in pp.jar indeed. I deleted the classpath I defined in the system and database access is granted nervertheless.