开发者

Unable to compile using additional library/jar file, javac classpath

开发者 https://www.devze.com 2023-02-18 14:42 出处:网络
I am trying to compile code with javac using the ojdbc6.jar from oracle. I have my source in \'src\' my .class in \'bin\' and my \'jar\' in includes.

I am trying to compile code with javac using the ojdbc6.jar from oracle.

I have my source in 'src' my .class in 'bin' and my 'jar' in includes.

my current javac command is:

javac -cp ".;./includes/ojdbc6.jar" src/*.java -d bin

this worked until I imported the driver in one of my source files. Now I get:

javac -cp ".;./includes/ojdbc6.jar" src/*.java -d bin
src/OracleSingleton开发者_如何学编程.java:1: package oracle.jdbc.driver does not exist
import oracle.jdbc.driver.OracleDriver;

I am sure the problem is with my classpath, any idea how to fix this. I have manually checked to see whether the file is there and it is.

also seeing as I haven't got this far I might as well preempt the next question, do I have to point to this jar when running the program too? if so how.

Many thanks


I'm not sure I see the problem, but here's a working example that might shed some light. I got the driver here.

import java.sql.*;
import java.util.*;

class DriveTest {
    public static void main (String args [])
        throws SQLException, ClassNotFoundException {
        System.out.println("Current JDBC Drivers: "
            + System.getProperty("jdbc.drivers"));
        Enumeration e = DriverManager.getDrivers(); 
        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
    }
}
$ javac -cp .:ojdbc6.jar DriveTest.java 
$ java -cp .:ojdbc6.jar DriveTest
Current JDBC Drivers: null
oracle.jdbc.OracleDriver@2666e815
$ jar tf ojdbc6.jar | grep OracleDriver
oracle/jdbc/OracleDriver.class
oracle/jdbc/driver/OracleDriver$1.class
oracle/jdbc/driver/OracleDriver.class
oracle/jdbc/driver/OracleDriverExtension.class

Addendum:

Looking closer, the DriverManager Service Provider mechanism specifies oracle.jdbc.OracleDriver. You should use that instead of oracle.jdbc.driver.OracleDriver.

$ cat META-INF/services/java.sql.Driver 
oracle.jdbc.OracleDriver


I think you should use -classpath instead of cp, that should solve the problem

0

精彩评论

暂无评论...
验证码 换一张
取 消