[英]java -jar myapp.jar includes ojdbc6.jar but throws ClassNotFoundException
java -jar myapp.jar
includes ojdbc6.jar
but throws the following exception java -jar myapp.jar
包含ojdbc6.jar
但抛出以下异常
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. 但是我需要构建一个要部署的jar文件。 Every time whichever way I build the jar that refers to, includes, has
classpath
for ojdbc6.jar
ends out throwing the same error. 每当我构建引用的jar包含时,
ojdbc6.jar
classpath
ojdbc6.jar
抛出相同的错误。 MyApp works fine in eclipse with ojdbc6.jar
in the project's Referenced Libraries
folder. MyApp在项目的
Referenced Libraries
文件夹中使用ojdbc6.jar
在eclipse中工作正常。
If you are using Maven, I would suggest using the shade plugin to create an uber jar. 如果您使用的是Maven,我建议使用shade插件创建一个超级jar。 http://maven.apache.org/plugins/maven-shade-plugin/
http://maven.apache.org/plugins/maven-shade-plugin/
This way you can be sure no required libraries / jar files are missing. 这样您就可以确保没有丢失所需的库/ jar文件。
If you cannot / do not want to use Maven, please provide the entire stack trace you get to help debug the problem. 如果您不能/不想使用Maven,请提供您可以帮助调试问题的整个堆栈跟踪。
Add -verbose:class
to the command line to had the JVM show what classes are being loaded. 在命令行中添加
-verbose:class
,让JVM显示正在加载的类。 If you don't see oracle.jdbc.driver.OracleDriver
printed out, then the ojdbc6.jar is probably not found. 如果您没有看到打印出
oracle.jdbc.driver.OracleDriver
,则可能找不到ojdbc6.jar。
Thanks everyone for your comments! 感谢大家的意见!
This worked: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html 这有效: 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): 关于-C选项的其他帖子提示不适合jar中其他jar的classpath,而是在create jar语句中引用ojdbc6.jar并在Manifest中使用Class-Path(行之间没有空格 - 这些是由Stack的编辑):
Manifest-Version: 1.0 清单 - 版本:1.0
Main-Class: MyApp 主类:MyApp
Class-Path: ojdbc6.jar Class-Path:ojdbc6.jar
Created-By: 1.7.0_71 (Oracle Corporation) 创建者:1.7.0_71(Oracle Corporation)
Now create jar statement looks like this: 现在创建jar语句如下所示:
jar cfm myjar.jar MANIFEST.MF MyApp.class Other1.class Other2.class Other3.class jar cfm myjar.jar MANIFEST.MF MyApp.class Other1.class Other2.class Other3.class
Regards, Chase 此致,大通
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.