简体   繁体   中英

java -jar myapp.jar includes ojdbc6.jar but throws ClassNotFoundException

java -jar myapp.jar includes ojdbc6.jar but throws the following exception

ClassNotFoundException: oracle.jdbc.driver.OracleDriver

The closest post I've found that works for me displays this solution for an individual class:

C:\Project\bin>java -classpath .;ojdbc6.jar MyApp

but I need to build a jar file to deploy. Every time whichever way I build the jar that refers to, includes, has classpath for ojdbc6.jar ends out throwing the same error. MyApp works fine in eclipse with ojdbc6.jar in the project's Referenced Libraries folder.

If you are using Maven, I would suggest using the shade plugin to create an uber jar. http://maven.apache.org/plugins/maven-shade-plugin/

This way you can be sure no required libraries / jar files are missing.

If you cannot / do not want to use Maven, please provide the entire stack trace you get to help debug the problem.

Add -verbose:class to the command line to had the JVM show what classes are being loaded. If you don't see oracle.jdbc.driver.OracleDriver printed out, then the ojdbc6.jar is probably not found.

Thanks everyone for your comments!

This worked: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Tipped off by other posts about -C option not suitable for classpath within the jar for other jars, rather take out reference to ojdbc6.jar in create jar statement and use Class-Path in Manifest (no spaces between lines--those were added by Stack's editor):

Manifest-Version: 1.0

Main-Class: MyApp

Class-Path: ojdbc6.jar

Created-By: 1.7.0_71 (Oracle Corporation)

Now create jar statement looks like this:

jar cfm myjar.jar MANIFEST.MF MyApp.class Other1.class Other2.class Other3.class

Regards, Chase

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