aspose file tools*
The moose likes Java in General and the fly likes Jar file exception due to not finding Oracle driver but other standalone programs can use it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar file exception due to not finding Oracle driver but other standalone programs can use it" Watch "Jar file exception due to not finding Oracle driver but other standalone programs can use it" New topic
Author

Jar file exception due to not finding Oracle driver but other standalone programs can use it

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 87
I have checked in some other threads but I don't know how to get my executable jar file to work as it fails due to the class not found exception when trying to connect to my Oracle database(oracle.jdbc.driver.oracledriver).

The jar file works when I exclude the oracle connection and outside of the jar file I can use the above driver in a standalone java program to connect to the database meaning that my programs can see the driver and the driver location is in my classpath so why then would my jar file be failing on this error?

It's something that I'm missing regards the jar file procedure and I have tried adding the oracle driver zip/jar file to my executable jar and adding the Class-Path entry to my manifest file (whether this is right or not) but it still gives the exception...( my manifest file by the way has the fully qualified name for the main class...which is fine)

So given that standalone programs on my computer see and can use the Oracle connection , what does it take for an executable jar file use the same?, because this is where it is currently failing...

Hope someone can help.

Thanks,

Colm
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

You have to put a Class-Path entry into the manifest of your executable jar which references the Oracle driver jar. And then you have to put the Oracle jar in the place which is referenced.

If you are running your executable jar via a command like "java -jar executable.jar" then the only way to put something into the classpath is via the executable jar's manifest. The same is true if you are double-clicking the executable jar to make it run.
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 87
Thanks for replying Paul.

My computer uses the classes12.zip file in its classpath for normally accessing the database. This is the oracle zip file containing those database access classes. I already had lines in my manifest file as follows:

Main-Class: java.test.ReadLog
(Where ReadLog is my class containing the main method)

Class-Path: classes12.zip
(where this is the file with my database access classes as used in my system classpath and this zip file is also packaged up in my jar having copied to the same location as my ReadLog.class)

Still, I get the class not found when it comes to try and access the database?


Do you have any further thoughts?



Thnaks,

Colm.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 973
    
    5

Taken from Oracle website:


The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.


This means your classpath entry in the manifest can only access classes/jars on the local file system, not those on a network or in the same jar file.
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 87
Thanks James.

'This means your classpath entry in the manifest can only access classes/jars on the local file system, not those on a network or in the same jar file.'

So, having the Oracle classes on my file system anyway, how do I get my executable jar to work with them?


Regards,

Colm.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 973
    
    5

Colm

You need to create your own manifest with entry:

Class-Path: /path/to/your/jar/classes12.zip

I'm not sure if you can use a zip file in this case but try it first.
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 87
Thanks again James.

I have classes12.zip in my classpath that standalone applications can use, in directory C:\Libs which is on my classpath. If I try to add as suggested

Class-Path: C:\Libs\classes12.zip

I get a new error about not being able to find my main class, not about the oracle class so it seems it does not like this format. I retried with a classes12.jar alternative (after converting zip to jar) and the same occurred.

Removing this again,I even tried to add the OracleDriver class to my current directory which is in the classpath and still the application fails with error about not finding oracle class.

I'm totally stuck now. Any more suggestions James or others?

Thanks,

Colm

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 973
    
    5

Colm

Can you post the full listing of the manifest you created?
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 87
Hello again.

Yes,here is the manifest file I used
Main-Class: java.test.ReadLog
Class-Path: C:\Libs\classes12.jar

Regards,
Colm
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 973
    
    5

Colm

Having taken another look at the docs surrounding entries for the Class-Path tag, it would appear they cannot be absolute but rather relative paths to your jar file.

So if your jar resides in C:\, the correct entry in the manifest should be:

Class-Path: Libs/classes12.jar
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 87
James,

Thanks very much for your help.

I copied my jar to C:\ and changed the Class-Path entry to Libs/classes12.jar (relative path) and it worked! or alternatively, copied the classes12.jar in to C:\ and just referenced it as classes12.jar in the Class-Path line.

From your earlier post, this Class-Path entry cannot reference another file in the jar file. In this case, for this to work on a different machine, I need to ensure that the classes12 is on that machine somewhere. I could in theory,package the classes12.jar in my executable jar, create a small batch file that runs on the other machine that extracts the classes12.jar to a given directory and reference this in the manifest file, Class-Path line, so that when the batch file comes to execute java -jar myJar, the other jar file is in the same directory.

Regards,

Colm.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar file exception due to not finding Oracle driver but other standalone programs can use it
 
Similar Threads
(NX)path of db file
setting classpath jar
Unable to execute jar file....got following stack trace.
Database can connect in Service Netbeans screen but not using code
Unable to execute jar file....got following stack trace.