Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

running from .jar file has missing classes  RSS feed

 
Carty Ellis
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
Carty Ellis
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked perfectly! Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!