 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Murat Tasan Guest
|
Posted: Mon Jul 14, 2003 2:56 pm Post subject: loading drivers |
|
|
I'm having a very confusing problem with my application...
The problem is when I try to load JDBC drivers when my app is in a jar file.
Here is a test case:
public class Test
{
public static void main(String[] args) throws Exception
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("sweet!");
}
}
Now, my $CLASSPATH is set fine, verified by running the above and getting:
Okay, so now I'll jar this file up and add a manifest addition...
(for the main class)...
| Quote: | jar -cmf MANIFEST.MF test.jar Test.class
|
now I try to run it:
| Quote: | java -jar test.jar
|
and it starts to run (so manifest is fine), but gives me this:
Exception in thread "main" java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at Test.main(Test.java:5)
And the $CLASSPATH has NOT changed at all while doing this.
So it worked when running from the .Class file, but not when running
from the .jar file
Any ideas? Am I just missing something here about .jar files?
Thanks much,
murat
--
Murat Tasan
[email]mxt6 (AT) po (DOT) cwru.edu[/email]
[email]tasan (AT) eecs (DOT) cwru.edu[/email]
[email]murat.tasan (AT) cwru (DOT) edu[/email]
http://genomics.cwru.edu
|
|
| Back to top |
|
 |
Jon Skeet Guest
|
Posted: Mon Jul 14, 2003 4:13 pm Post subject: Re: loading drivers |
|
|
Murat Tasan <tasan (AT) eecs (DOT) cwru.edu> wrote:
| Quote: | And the $CLASSPATH has NOT changed at all while doing this.
So it worked when running from the .Class file, but not when running
from the .jar file
|
The classpath environment variable (and command line option) isn't used
when the -jar option is specified.
--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
|
|
| Back to top |
|
 |
Murat Tasan Guest
|
Posted: Mon Jul 14, 2003 5:08 pm Post subject: Re: loading drivers |
|
|
okay, well then, that sucks.
does anyone know then how to specify additional classpaths when using the
-jar option?
i assume the java sdk classes are automatically included (they have to),
and all of the classes in the executing jar file... but how do i then load
classes not in either of those two locations?
thanks for all the help!
murat
On Mon, 14 Jul 2003, Jon Skeet wrote:
| Quote: | Murat Tasan <tasan (AT) eecs (DOT) cwru.edu> wrote:
And the $CLASSPATH has NOT changed at all while doing this.
So it worked when running from the .Class file, but not when running
from the .jar file
The classpath environment variable (and command line option) isn't used
when the -jar option is specified.
|
--
Murat Tasan
[email]mxt6 (AT) po (DOT) cwru.edu[/email]
[email]tasan (AT) eecs (DOT) cwru.edu[/email]
[email]murat.tasan (AT) cwru (DOT) edu[/email]
http://genomics.cwru.edu
|
|
| Back to top |
|
 |
Jon Skeet Guest
|
Posted: Tue Jul 15, 2003 7:26 am Post subject: Re: loading drivers |
|
|
Murat Tasan <tasan (AT) eecs (DOT) cwru.edu> wrote:
| Quote: | okay, well then, that sucks.
|
No, it doesn't. It means that people can distribute jar files without
worrying about whether someone will have some other version of a
library they need on their classpath.
| Quote: | does anyone know then how to specify additional classpaths when using the
-jar option?
|
Either use the extensions mechanism, or specify the classpath in the
manifest.
| Quote: | i assume the java sdk classes are automatically included (they have to),
and all of the classes in the executing jar file... but how do i then load
classes not in either of those two locations?
|
See above - or create a ClassLoader instance explicitly which knows how
to load the classes. In the case of a database, however, I believe it's
problematic if you end up with drivers being loaded by child
classloaders - hopefully someone here will have a solution for that if
it's an issue for you though.
--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|