aspose file tools
The moose likes Beginning Java and the fly likes running from .jar file has missing classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "running from .jar file has missing classes" Watch "running from .jar file has missing classes" New topic
Author

running from .jar file has missing classes

Carty Ellis
Greenhorn

Joined: Oct 04, 2003
Posts: 20
I am creating my first .jar file and having bad luck. I can execute my application normally, and it runs. When I jar it it cannot find my Oracle JDBC driver. To me, it seems if the Oracle .jar (classes12.jar) was not in the classpath I wouldn't be able to execute by just saying "java TextAreaAudit". It connects to the database and retrieves data. "java -jar appl.jar" opens the Swing window, but returns a ClassNotFoundError and mentions the Oracle JDBC driver - so that is what I assume is not found. What have I missed? I've been following Chapter 16 in "Head First Java" and I'm stumped. Should be simple (famous last words).
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

You will need to either place the Oracle.jar file in your classpath or unjar Oracle.jar and then jar its contents up along with your stuff. You cannot place a jar within a jar and have it work. I suspect that is what you probably did.
Carty Ellis
Greenhorn

Joined: Oct 04, 2003
Posts: 20
I have the Oracle.jar in the classpath. The application wouldn't work if it wasn't there - I am executing in directory C:\j2sdk1.4.2_03\demo\Test with the command "java TextAreaAudit" and the applicatioon performs just fine. I thought the classpath was the problem, hence the trial of executing from that directory.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

If you run an application with "java -jar", the jar is cconsidered to be "closed." Java won't look on the CLASSPATH for any additional classes. It will look in the jar, in the system classes, and in the standard extensions directory (JAVA_HOME/jre/lib/ext) and nowhere else. You can either put the JDBC driver into the "ext" directory, or you can use "java -classpath foo.jar MyClassName" instead of "java -jar foo.jar."


[Jess in Action][AskingGoodQuestions]
Carty Ellis
Greenhorn

Joined: Oct 04, 2003
Posts: 20
"java -classpath appl.jar TextAreaAudit" returns the same error. My classpath statement is: ".;C:\oracle\ora90\jdbc\lib\classes12.jar;C:\ApacheOrg\commons-lang-2.0\commons-lang-2.0.jar"
Thw Swing Panel opens, I press the button to have the database access occur and the message ClassNotFoundException: oracle.jdbc.driver.OracleDriver is displayed in the Text box by my Try-Catch.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

Yes, right. Sorry, I was sloppy in my answer. If you explicitly specify the classpath, then it should include the Oracle jar too, since under these circumstances CLASSPATH won't be used, either!
So use, literally,
java -classpath "appl.jar;.;C:\oracle\ora90\jdbc\lib\classes12.jar;C:\ApacheOrg\commons-lang-2.0\commons-lang-2.0.jar"
TextAreaAudit
and it should work.
Carty Ellis
Greenhorn

Joined: Oct 04, 2003
Posts: 20
Worked perfectly! Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running from .jar file has missing classes
 
Similar Threads
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Web Application Class Loader and Weblogic
JDBC - Connection Refused Error. Connecting (trying) to Oracle DB.
problem with classpath
thin driver / classpath / jdk1.4