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

Accessing jar file in classpath  RSS feed

 
Steve Campbell
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use the TableExample.jar which is part of the j2sdk samples (in jdk1.4\mode\jfc\TableExample).
I downloaded the latest oracle thin driver and created a classpath statement (in Windows XP) of "c:\oracle\ojdbc14.jar".
When I try to execute (via dos command box) using: java -jar TableExample.jar, The dialog window pops up, and I enter the name, password, db url (jdbc racle:thin:@eaidev1:1527 evexe), and driver (oracle.jdbc.driver.OracleDriver).
I get:
Cannot find the database driver classes.
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Can someone please tell me what I doing wrong?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run an executable JAR file, as you are doing, the JRE ignores the system's CLASSPATH setting, and just uses the CLASSPATH specified in the manifest of the JAR file.
You could add the TableExample.jar to your CLASSPATH, and then specify the proper class with the main method in TableExample.jar to run. So, if the manifest in TableExample.jar says that Foo is the main class, then after adding TableExample.jar to your CLASSPATH, you should be able to run things with java Foo
Any luck?
[ December 31, 2003: Message edited by: Dirk Schreckmann ]
 
Steve Campbell
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That fixed it. Thanks for your help!
Steve
 
Steve Campbell
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be more appropriate for the IDE's section, but I took the TableExample Java programs from the j2sdk folders, and created a project in Eclipse. I was able to add the correct files to make it run properly in Eclipse.
My question is when I create a Jar file in Eclipse (or any IDE), would I create a reference to the external jar file containing the Oracle db drivers in the project, and try to distribute it as part of the Jar file, or, if I wanted to distribute to coworkers, would I have to modify the classpath variable on their machines for my Jar file (in addition to the Oracle Jar). I wasn't able to figure out how to add a Classpath line in the Manifest file in the Jar file using Eclipse.
How do people usually do this?
Thanks,
Steve
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to adjust the system CLASSPATH settings on the machines where a JAR is to be deployed.
You'd likely want to include the dependencies inside of the distributed JAR you'd create.
Take a look at the later parts of the Creating An Executable JAR File thread for details on how to do such a thing.
 
Steve Campbell
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. I think I may try the Jar within a Jar.
Thanks,
Steve
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!