Oracle driver within a jar?

25 views
Skip to first unread message

stinkinrich88

unread,
Jul 18, 2007, 5:58:32 AM7/18/07
to The Java Posse
Hello

Basically, I'm using Eclipse to make an app that connects to a
database. To connect, it first loads the oracle driver with the
following code:

try{Class.forName("oracle.jdbc.driver.OracleDriver");}
catch (ClassNotFoundException e){
e.printStackTrace();
System.out.println("Error loading oracle driver, check your
classpath");
System.exit(1);
}


Works fine!! ...in Eclipse. But when I get Eclipse to package it into
a jar for me, it give me this exception:

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:
276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at engine.Billing.main(Billing.java:96)

The main class is in a folder called 'engine' and the oracle driver
(ojdbc14.jar) is in a folder called 'ExternalJars'.

I can run the program fine outside of Eclipse by using: java -
classpath .:./ExternalJars/* engine/Billing

But I'm still stuck getting it to work in a jar file. Any ideas??

p.s. are all classes / jars within a jar file automatically included
in the classpath? or do I need to do something with the manifest?

thanks!
Richard

Marcelo Fukushima

unread,
Jul 18, 2007, 8:40:07 AM7/18/07
to java...@googlegroups.com

the jars are not included because as of now, you cant embed jars
inside another jar, unless you use things like jarjar or fatjar
(google fatjar eclipse plugin for a hint)

>
> thanks!
> Richard
>
>
> >
>


--
[]'s
Marcelo Takeshi Fukushima

stinkinrich88

unread,
Jul 18, 2007, 8:58:27 AM7/18/07
to The Java Posse
Ahh I see! So that's why it isn't working.

Ok, so what is the done thing? Have a directory with lots of jars in
it and have the user unzip them onto their hard drive?

if so, I take it I would have to change the classpath in the manifest
for the main jar? I've tried this but it still gives the same error:

Manifest-Version: 1.0
Class-Path: .:ojdbc14.jar:jcalendar-1.3.2.jar

Main-Class: engine.Billing

thanks!

On Jul 18, 1:40 pm, "Marcelo Fukushima" <takesh...@gmail.com> wrote:

stinkinrich88

unread,
Jul 18, 2007, 9:32:13 AM7/18/07
to The Java Posse
Problem solved!

Thanks to Marcelo Fukushima, I learned that a jar cannot be nested in
a jar file.

I kept all my jars in the same directory and edited the mainfest from
the main jar to this:

Manifest-Version: 1.0
Class-Path: ojdbc14.jar jcalendar-1.3.2.jar

Main-Class: engine.Billing

Unlike from a command line, different jar files in the class path need
to be separated by white spaces.

also, you can not mix -jar option with -classpath option when running
a jar file, all classpaths need to be put in the manifest

thanks for helping!! (I'd still like to know if it is the 'done thing'
to have many jars in a directory)

thanks!

On Jul 18, 1:58 pm, stinkinrich88 <stinkinric...@googlemail.com>
wrote:

Todd Costella

unread,
Jul 18, 2007, 10:14:22 AM7/18/07
to java...@googlegroups.com
Yes, it is very common to have many jar files deployed with your
application.

There is a good introduction to jar files and related topics on the Sun
tutorial site.

http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

It's really important to understand the classpath and how the JVM
resolves classes.

Good luck.

Todd

Reply all
Reply to author
Forward
0 new messages