Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / September 2004

Tip: Looking for answers? Try searching our database.

calling database driver from .jar file

Thread view: 
Michael Baran - 24 Sep 2004 22:22 GMT
Hi All,

I have a java .class file which I have packaged into a .jar file.
The class connects to our oracle DB using one of the Oracle thin
drivers.

This works fine from outside of the jar file.  The driver is the
CLASSPATH and the  .class file works fine.

However, after packaging the class into a jar and running the jar, I
get the following error.

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
       at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:141)
       at SQLCommands.connectSPINS(SQLCommands.java:440)
       at multiInsert04.validateUserID(multiInsert04.java:594)
       at multiInsert04.insertDirs(multiInsert04.java:66)
       at multiInsert04.main(multiInsert04.java:668)

Is there are way to package the driver within the jar file to prevent
this error?
hilz - 24 Sep 2004 22:30 GMT
> Is there are way to package the driver within the jar file to prevent
> this error?

looks like the driver jar is not included in the classpath.
you need to add the driver jar in your class path, and i can think of two
places:
1) either in the launching command
2) or in the mainfest file or your application jar
hilz - 24 Sep 2004 22:31 GMT
> > Is there are way to package the driver within the jar file to prevent
> > this error?
[quoted text clipped - 4 lines]
> 1) either in the launching command
> 2) or in the mainfest file or your application jar

correction:
2) or in the mainfest file OF your application jar
David G - 24 Sep 2004 23:20 GMT
> > > Is there are way to package the driver within the jar file to prevent
> > > this error?
[quoted text clipped - 7 lines]
> correction:
> 2) or in the mainfest file OF your application jar

So, thats what that file is for :)
hilz - 25 Sep 2004 05:13 GMT
> So, thats what that file is for :)

which file is for what?
if you're talking about the manifest file, it is for this, and more.
see
http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html
Gerard Krupa - 27 Sep 2004 08:52 GMT
> Hi All,
>
[quoted text clipped - 7 lines]
> However, after packaging the class into a jar and running the jar, I
> get the following error.

If you're running the .jar file using the -jar flag then any classpath
specified on the command-line on in an environment variable will be
ignored.  You can either add a classpath entry in the manifest (already
mentioned elsewhere in this thread) or use the boot class path with the
-Xbootclasspath/a: flag.

HTH
Gerard


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.