Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executable jar can't find mysql-jdbc driver class

 
Greg Levine
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've written a program that takes data from some xml files stored on a server and populates a database with the data. I started by developing in Eclipse 3.2.0 on Windows XP Professional using JDOM for parsing the xml and MySQL Connector/J 3.1 for database connectivity.

When installing MySQL Connector/J 3.1 the instructions (linked from dev.mysql.com, http://www.developer.com/java/data/article.php/3417381#Installation_and_Preparation_of_MySQL) mentioned three methods for using the driver. Following the tutorial, I chose the option in which the jar file named mysql-connector-java-3.0.17-ga-bin.jar is copied into the folder named C:\java\j2sdk1.4.2_12\jre\lib\ext. The tutorial claimed that this made it unnecessary to add this jar to the classpath.

I completed and tested the program in Eclipse and was satisfied with the results, so I chose to go to the next step. Using Ant I wanted to create an executable jar that will run my program. I was able to create the executable jar, but it threw the following exception:



Clearly the JDBC driver class can't be found. Assuming this was because I might have to actually add the jar file to the classpath I went ahead and edited the classpath to include C:\java\j2sdk1.4.2_12\jre\lib\ext\mysql-connector-java-3.0.17-ga-bin.jar. I rebuilt the executable jar and tried again. Same exception thrown.

I then deleted the jar file in C:\java\j2sdk1.4.2_12\jre\lib\ext\ and changed the classpath to use C:\java\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga-bin.jar. I tried again and it failed again.

I returned to working in Eclipse this time without the jar in the classpath or in C:\java\j2sdk1.4.2_12\jre\lib\ext\ and of course it failed once more.

I put the jar back in C:\java\j2sdk1.4.2_12\jre\lib\ext\ and in the classpath. This time I added a line to the build file to copy the jar and paste it in the directory where my executable jar would be run from. I had done this with the JDOM jar, so I was hoping it would work in this case too. But it didn't.

At this point I am completely confused. My Google searches for solutions to this problem have turned up nothing and none of my resource books have any useful information for solving this problem. I was hoping that someone on these forums might have a suggestion for fixing this bug.

Thanks in advance for advice you are able to give me.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. show the code that loads the driver.
2. Are you sure thats the JRE you are running your program from _within_ eclipse with? Check your launch configuration.
 
Greg Levine
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

1.

2. According to Eclipse, the installed JRE's are j2sdk1.4.2_12 and jre1.5.0_06. I have j2sdk1.4.2_12 checked, so it is added to the build path of newly created Java projects by default. And looking at the build path in the project properties I see that j2sdk1.4.2_12 is the JRE System Library on the libraries tab.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.

Building the program has nothing to do with running it. What JRE is referenced in your launch configuration when you run the project?

When you push the debug/run button to the right should be a tiny arrow. Push that and go to Debug... or Run...

Then see what JRE your launch configuration is using.
[ August 10, 2006: Message edited by: Mr. C Lamont Gilbert ]
 
Greg Levine
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhhh, thanks for clearing that up. The Project JRE is j2sdk1.4.2_12. Further investigation also showed that C:\java\j2sdk1.4.2_12\bin\javaw.exe is being called to run the program.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic