MyException - 我的异常网
当前位置:我的异常网» J2SE » 对clazz.getResource("")的困惑,请朋友

对clazz.getResource("")的困惑,请朋友们解惑,多谢(2)

www.MyException.Cn  网友分享于:2013-12-15  浏览:2597次

=====oracle.jdbc.driver.OracleDriver=====
1 jar:file:/D:/SYJ.WORK/SYJ.LIB/driver/oracle-connector/ojdbc14_g.jar!/oracle/jdbc/driver/
2 file:/D:/SYJ.WORK/SYJ.WORKSPACE/ws1/cl2/bin/
3 file:/D:/SYJ.WORK/SYJ.WORKSPACE/ws1/cl2/bin/
4 null



------解决方案--------------------
先帮顶一个
------解决方案--------------------
你都是在 Eclipse 的 Export 下进行打包的吧。

你用 Ant 或者 jar 工具进行打包,看看结果是不是这样呢?

下面是我用 Ant 打包,之后运行那个 bat 的结果(注:我用的是 MySql 的 JDBC 驱动):

Java code
java -jar cl2.jar调用**************************************************
D:\test
=====test.Main=====
1 jar:file:/D:/test/cl2.jar!/test/
2 null
3 null
4 null
D:\test
=====com.mysql.jdbc.Driver=====
1 jar:file:/D:/test/mysql-connector-java-5.1.5-bin.jar!/com/mysql/jdbc/
2 null
3 null
4 null
D:\test
=====com.bao.A=====
1 jar:file:/D:/test/cl1.jar!/com/bao/
2 null
3 null
4 jar:file:/D:/test/cl1.jar!/com/bao/test.txt
将cl2.jar添加到CLASSPATH中
java test.Main调用**************************************************
D:\test
=====test.Main=====
1 jar:file:/D:/test/cl2.jar!/test/
2 file:/D:/test/
3 file:/D:/test/
4 null
D:\test
=====com.mysql.jdbc.Driver=====
1 jar:file:/D:/test/mysql-connector-java-5.1.5-bin.jar!/com/mysql/jdbc/
2 file:/D:/test/
3 file:/D:/test/
4 null
D:\test
=====com.bao.A=====
1 jar:file:/D:/test/cl1.jar!/com/bao/
2 file:/D:/test/
3 file:/D:/test/
4 jar:file:/D:/test/cl1.jar!/com/bao/test.txt

------解决方案--------------------
超出我的理解范围了
------解决方案--------------------
关注一下
------解决方案--------------------
public static void main(String[] args) {
println(Main.class);
System.out.println("---------------------");
println(test.Main.class);

运行了一下:
打包jar:
E:\workspace1\t11\bin>java -jar c12.jar
=====test.Main=====
1 jar:file:/E:/workspace1/t11/bin/c12.jar!/test/
2 null
3 null
4 jar:file:/E:/workspace1/t11/bin/c12.jar!/test/test.txt
---------------------
=====test.Main=====
1 jar:file:/E:/workspace1/t11/bin/c12.jar!/test/
2 null
3 null
4 jar:file:/E:/workspace1/t11/bin/c12.jar!/test/test.txt
=====test.A=====
1 jar:file:/E:/workspace1/t11/bin/c12.jar!/test/
2 null
3 null
4 jar:file:/E:/workspace1/t11/bin/c12.jar!/test/test.txt
ClassNotFound :oracle.jdbc.driver.OracleDriver

eclipse :
=====test.Main=====
1 file:/E:/workspace1/t11/bin/test/
2 file:/E:/workspace1/t11/bin/
3 file:/E:/workspace1/t11/bin/
4 file:/E:/workspace1/t11/bin/test/test.txt
---------------------
=====test.Main=====
1 file:/E:/workspace1/t11/bin/test/
2 file:/E:/workspace1/t11/bin/
3 file:/E:/workspace1/t11/bin/
4 file:/E:/workspace1/t11/bin/test/test.txt
=====test.A=====
1 file:/E:/workspace1/t11/bin/test/
2 file:/E:/workspace1/t11/bin/
3 file:/E:/workspace1/t11/bin/
4 file:/E:/workspace1/t11/bin/test/test.txt
ClassNotFound :oracle.jdbc.driver.OracleDriver

cmd下运行:
E:\workspace1\t11\bin>java test.Main
=====test.Main=====
1 file:/E:/workspace1/t11/bin/test/
2 file:/E:/workspace1/t11/bin/
3 file:/E:/workspace1/t11/bin/
4 file:/E:/workspace1/t11/bin/test/test.txt
---------------------
=====test.Main=====
1 file:/E:/workspace1/t11/bin/test/
2 file:/E:/workspace1/t11/bin/
3 file:/E:/workspace1/t11/bin/
4 file:/E:/workspace1/t11/bin/test/test.txt
=====test.A=====
1 file:/E:/workspace1/t11/bin/test/
2 file:/E:/workspace1/t11/bin/
3 file:/E:/workspace1/t11/bin/
4 file:/E:/workspace1/t11/bin/test/test.txt
ClassNotFound :oracle.jdbc.driver.OracleDriver

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有