开发者

How do I compile a Jar w/ a external lib

开发者 https://www.devze.com 2023-04-04 03:08 出处:网络
Well I\'m new to to stackoverflow so I\'m sorry if I misinterpreted some of this Q&A rules feel free to point out any mistake, and for my English, since I\'m not an English native speaker.

Well I'm new to to stackoverflow so I'm sorry if I misinterpreted some of this Q&A rules feel free to point out any mistake, and for my English, since I'm not an English native speaker.

Now, although I program for several years, I've been forced to use an old version of JDeveloper on this project I'm in, and I've had some beginner issues, because I'm used to let the IDE do all the hard work.

My objective is, to compile my project to a jar and execute it in the server.

So far, I got my app to run and work on my IDE which is JDev 9.0.3.2开发者_如何学运维 (OLD) and Java version is 1.3.1_01, but when I try to compile to a jar file for some reason the lib doesn't come along.

My code (partially ofc):

Connection con = null;

public Depositos() throws Exception {

        System.out.println("Beginning ORACLE DB connection");

        try {
            String connstr="jdbc:oracle:thin:"+"@<hostname>"+":"+"<port>"+":"+"<SID>";
            System.out.println("connstr ok");

            Class.forName("oracle.jdbc.driver.OracleDriver");

            System.out.println("Class.forName ok");
            con = DriverManager.getConnection (connstr, "cic", "managercic");

            System.out.println("Connection successful");              
        } catch (ClassNotFoundException e) {
              throw new Exception("DB connection error "+e.getMessage());
        }

    }

And I suspect the problem is over here, more precisely in here: "Class.forName("oracle.jdbc.driver.OracleDriver"); "

My procedure is: On the Depositos.java folder

I run this:

javac -verbose Depositos.java -classpath C:\oracle\ora92\jdbc\lib\classes12.jar

the output says it's all OK.

jar cfmv0 Depositos.jar MANIFEST.MF Depositos.class C:\oracle\ora92\jdbc\lib\classes12.jar

my MANIFEST.MF contains:

Manifest-Version: 1.0
Created-By: Oracle JDeveloper 10.1.3.4.0
Main-Class: Depositos.Depositos

When I run the code from the src folder with:

java oic.OIC

my output is:

Beginning ORACLE DB connection
connstr ok
Exception in thread "main" java.lang.Exception: DB connection error oracle.jdbc.driver.OracleDriver
at Depositos.Depositos.<init>(Depositos.java:47)
at Depositos.Depositos.main(Depositos.java:98)

Which leads me to the conclusion that the error is in the line I stated above.

And I don't understand what I did wrong, I've read so many post from other forums, I don't know what's the right move anymore.

I tried several combinations of compiling commands.

Thank you for your help.


You can add the oracle jar to your jar, and put a 'Class-path' attribute in the manifest.

Manifest-Version: 1.0
Created-By: Oracle JDeveloper 10.1.3.4.0
Main-Class: Depositos.Depositos
Class-path: <path to jar inside your jar>

From memory though, if your jar is signed, you need to sign the jars within it also.

0

精彩评论

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

关注公众号