简体   繁体   中英

Java:Cannot load main class with jar file using classpath

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)

根据JAR文件规范 (在“主要属性”下,“类路径”下,路径应该是相对的而不是绝对的。因此,如果将oracle jdbc jar复制到jar文件所在的目录,并将路径更改为“ ojdbc14 .jar”,它应该可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM