473,585 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program can't find class in .jar file

46 New Member
I have a Java program that is deployed as a .jar file in which is another .jar file with the mysql library. Here is the appropriate section of code:

Expand|Select|Wrap|Line Numbers
  1.    /**
  2.     * Makes the connection to the database.
  3.     */
  4.    protected static Connection makeConnection()
  5.    {
  6.       try
  7.       {
  8.          Class.forName("org.gjt.mm.mysql.Driver");
  9.  
  10.          database = DriverManager.getConnection(
  11.                dataBaseName, dbAccessUserId, dbAccessPwd);
  12.       }
  13.  
  14.       catch (SQLException sqle)
  15.       {
  16.          System.out
  17.                .println("Error while connection attempt!");
  18.          sqle.printStackTrace();
  19.       }
  20.       catch (ClassNotFoundException e)
  21.       {
  22.          System.out.println("Jdbc Driver not found: "
  23.                + e.getMessage());
  24.          e.printStackTrace();
  25.       }
  26.  
  27.       return database;
  28.    }
When I execute the .jar file, I get this error message and trace:

Jdbc Driver not found: org.gjt.mm.mysq l.Driver
java.lang.Class NotFoundExcepti on: org.gjt.mm.mysq l.Driver
at java.net.URLCla ssLoader$1.run( Unknown Source)
at java.security.A ccessController .doPrivileged(N ative Method)
at java.net.URLCla ssLoader.findCl ass(Unknown Source)
at java.lang.Class Loader.loadClas s(Unknown Source)
at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
at java.lang.Class Loader.loadClas s(Unknown Source)
at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
at java.lang.Class .forName0(Nativ e Method)
at java.lang.Class .forName(Unknow n Source)
at gov.nasa.jsc.fc od.asp3.gII_sim ulator.user_int erface.jdbc.GII DatabaseM
Some how the code in the main .jar file is not finding the Driver class embedded in the .jar file containing the mysql library.

Does anyone know how to access this library .jar file?

Thanks in advance.
Aug 2 '07 #1
4 7066
JosAH
11,448 Recognized Expert MVP
Does anyone know how to access this library .jar file?
Yep, simply mention that jar file (and the path to it) in your classpath variable.

kind regards,

Jos
Aug 3 '07 #2
PaperPilot
46 New Member
Yep, simply mention that jar file (and the path to it) in your classpath variable.

kind regards,

Jos
I have tried every possible form of the CLASSPATH system variable including the path to another version of mm_mysql-2_0_4-bin.jar to no avail. My problem is something other than the CLASSPATH.

Thanks.
Aug 3 '07 #3
JosAH
11,448 Recognized Expert MVP
I have tried every possible form of the CLASSPATH system variable including the path to another version of mm_mysql-2_0_4-bin.jar to no avail. My problem is something other than the CLASSPATH.

Thanks.
If it is another problem then you didn't spell "org.gjt.mm.mys ql.Driver" correctly.
I can't tell from here; the jvm simply searches all lasspath entries for a fully
qualified class name. If the class is stored on the file system directly then the
classloader assumes the package components to be directories descending
from one of the classpath entries. Otherwise, when you mentioned a .jar file as
a classpath entry, the classloader seaches the jar for your fully qualified class
name.

A last option is that your classpath is correct and you spelt the name of the class
correctly but the class simply isn't there.

kind regards,

Jos
Aug 3 '07 #4
praveen2gupta
201 New Member
Hi
Put the driver jar file library.jar in the folder of your code. Now create a jar file of your code and write also the name of library.jar along with the classes name.

The jar file can contain another jar file within it.
Aug 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2404
by: Sean Cleary | last post by:
In Java How to program, 5th edition, I can not get past the example in chapter 3, page 89 to page 96. Is there some errata for this? I did not/could not load all the tools. I am coming from Slick edit and from Dos, and they both say that my copying of that example is flawed. Now I made a change: the name of the file is Lab2.java, the html...
33
3469
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually write a program or a project of some sort, how do you actually start. Picture this, you know what you want the program to do (its features), you have...
6
2576
by: Stefania Scott | last post by:
Hi, I need to find how can I know that a program I am going to shell it is already open. This program uses an csv file that I need to refresh before shelling the program, however if the csv file is already in use because the program is open I cannot refresh it (kill it and rewrite it) and I do not get any error message. Right now I have a...
27
2069
by: cj | last post by:
I run this program and to exit click the X in the upper right corner. But apparently it isn't really ending the program. If I return to VB and make changes then try to rebuild the app it says the exe is still in use--I find it is still a process in Task Manager. What do I need to do to make clicking that X actually end the program? ...
0
2495
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com http://www.livingcosmos.org/Members/sundevil/python/articles/a-comparison-of-python-class-objects-and-init-files-for-program-configuration/view
11
7686
by: hamiltongreg | last post by:
I am new to Java and am having problems getting my program to compile correctly. My assignment is as follows; Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software). • Create a product class that holds the item number, the name of the product, the...
18
3854
by: Neehar | last post by:
Hello For one of the interviews I took recently, I was given an offline programming quiz. In 30 minutes I had to write code in C++ to counts the number of times each unique word appears in a given file. I tried my level best even after the quiz to come up with a solution but cudnt find an efficient one. :( This is what I did.
1
6008
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main function which i think has problem // this a simple program about phonebook,it can add items,del items,find items and #include "member.h" #include...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.