According to JAR File Specification (Under "Main Attributes", "Class-Path" the path should be relative not absolute. So if you copy the oracle jdbc jar to the same directory as your jar file, and change the path to just "ojdbc14.jar", it should work.
Java:Cannot load main class with jar file using classpath
-
14-07-2023 - |
Question
I am getting error while executing a jar file. I have set my manifest file with a new line and it looks like this:
Main-Class: Demo
Class-Path: C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar .
My Main class name is Demo and it is in the current working directory.
When I execute jar cfm Project.jar manifest.txt *.class
My Error is:
Error: Could not find or load main class Demo
There is no problem with main classname and executing Directory because when I execute the jar file without classpath I get:
Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at Demo.main(Demo.java:8)
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow