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.
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.
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:
(Where ReadLog is my class containing the main method)
(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?
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.
'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?
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
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 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.