File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Fun with Classpaths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Fun with Classpaths" Watch "Fun with Classpaths" New topic
Author

Fun with Classpaths

Zachary Anderson
Ranch Hand

Joined: Oct 14, 2005
Posts: 49
Hello JavaRanch,
I was hoping someone would be willing and able to help me with a classpath problem I'm having.
I had written here previously with a database-connection problem, in which the program couldn't write to the database. A few months later the company hired a specialist to look at it, and he enabled the database connection by changing the order of items in the classpath.
I am perfectly willing to do my own work, but I have no idea where to start. I want to do one of four things: Be able to change the order of JBuilder's classpath so the sql-connector is added first, change the compilation order in the jar so it loads the sql-connector first, make the .bat file more portable so I can load just one file rather than setting up a directory structure for the .bat to look at, or figure out why the order-of-loading matters and resolve any conflict between myprogram and the mysql-connector. If anyone could share any insight into any of these possible solutions, or at least a place for me to start reading, I'd be a very happy person.

I'm doing most of my work with JBuilder. JBuilder put its classpath (which runs on its own but doesn't connect successfully and can't save results) together as such (probably with lots of extraneous stuff):

The successful classpath was written as the following .bat file:

... aaand the Manifest for the Jar I previously created with JBuilder is as follows:
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
Well at first glance I see 3 versions of the mysql jar. I would get all but one of them out of the build path and out of the class path. Apparently mysql-connector-java-3.1.8-bin.jar was the one that worked, I'd stick with it.

I would get mysql-connector-java-3.1.8-bin.jar out of the src directory as thats probably confusing things even more. I'd create a lib directory and put all third party required jars in there.

From there you can either list the jars in your Class-Path of the manifest file as lib/thejar.jar and use java -jar to start the program or you can create a batch file very much like the one you describe and launch your program with the classname.

Good luck!
Zachary Anderson
Ranch Hand

Joined: Oct 14, 2005
Posts: 49
Hello again, Tim!
Yeah, I have no clue why JBuilder decided to pull in 3.1.12. I found a way to cut it from the classpath, although I still can't figure out how to change the order of the classpath so 3.1.8 comes before myprogram.
Good news, moving the 3.1.8 jar out of Code and into jre.lib has stopped it from getting the "NoClassDefFound" run-time error for Driver.class. (Only shows up when a database is specified.) Unfortunately, the other problems,

are still bouncing back when I try to get it into a database.
I'm going to poke around with directory structure a bit more to see if there's another (unusable) version of MySQLDriver that's being loaded when myprogram is loaded first.
Thanks for the brains,
Zachary

Originally posted by Tim LeMaster:
Well at first glance I see 3 versions of the mysql jar. I would get all but one of them out of the build path and out of the class path. Apparently mysql-connector-java-3.1.8-bin.jar was the one that worked, I'd stick with it.

I would get mysql-connector-java-3.1.8-bin.jar out of the src directory as thats probably confusing things even more. I'd create a lib directory and put all third party required jars in there.

From there you can either list the jars in your Class-Path of the manifest file as lib/thejar.jar and use java -jar to start the program or you can create a batch file very much like the one you describe and launch your program with the classname.

Good luck!
Zachary Anderson
Ranch Hand

Joined: Oct 14, 2005
Posts: 49
Programmer's definition of progress: A different error message than last time

Actually, it's working. I've found and removed a duplicated filename (which was loaded first by JBuilder but not when the classpath specifically asked it to do otherwise).

Indirectly, this explains why the mini-program I made last time worked; it was fairly bare-bones, so it didn't have that extra file.

Still a little cleaning up to do, but that's how it went. Thanks for Tim for the brains this time around, and the 'Ranch at large for the brains last time and the handy place to harvest them all. Hopefully someday I'll be proficient enough to give brains to someone else.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fun with Classpaths