Results 1 to 15 of 15
- 12-30-2008, 03:38 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
How to get Jar files to work with Databases
Hey all,
I made a cool little database program with the latest version of mysql connector j.
When I compile it, it works great. But, when compress it into a .jar file (runnable program file), it doesn't work.
There must be something I'm doing wrong. Do I need to put the mysql-connector .jar file somewhere?
I know how to find my Manifest.MF file. But I don't know what to do with it. (I've heard there's something that I gotta do with that).
Have I searched google? Yes, but none of it helps much. I think some direct help is needed.Last edited by hunterbdb; 12-30-2008 at 03:46 AM.
- 12-30-2008, 10:03 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 12-30-2008, 05:35 PM #3
You can either include everything from the MySQL JAR into your JAR, or you can include both JAR's in your classpath on the java command. Typically, the second choice is preferred.
- 12-30-2008, 07:02 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Or simply place the mysql driver jarfile in the proper place (depends on how you do the next step) and configure the manifest file correctly, so you can simply execute java -jar yourfile.jar (or "double-click" as everyone seems to like to refer to it).
Edit: Which the tutorial posted covers, of course.Last edited by masijade; 12-30-2008 at 07:04 PM.
- 12-31-2008, 10:19 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
a booga wooga wooga woo!
P.S. English only, please. And, since I seemingly don't have the font that is needed to display it, I don't even know what language it is you used. And "70000" what? As that (the first word of none title text) was the only thing that could be read, as an actual word/number, here.
- 12-31-2008, 09:00 PM #6
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
okay, great, but the tutorial did not help at all. can somone simply tell me how to add a classpath to the jar? Where do I put the mysql .jar?
look at my .jar file:

Where does the mysql .jar file go?
- 12-31-2008, 09:04 PM #7
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
- 12-31-2008, 09:29 PM #8
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
I get this error when I try to run my .jar file:
- 01-01-2009, 01:21 AM #9
Member
- Join Date
- Jul 2008
- Posts
- 68
- Rep Power
- 0
There is an attribute called "Class-Path" that you can specify in the manifest of your jar. Add the mysql jar to this attribute and you should now have access to the classes contained in the mysql jar.
- 01-01-2009, 10:57 AM #10
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
It didn't. Yes it does, you didn't bother to read it all.
Check Working with Manifest Files: The Basics (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
Specifically Adding Classes to the JAR File's Classpath (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
Any where you want to so long as it is referenced in the manifest file.Where do I put the mysql .jar?Last edited by masijade; 01-01-2009 at 11:00 AM.
- 01-01-2009, 10:35 PM #11
Member
- Join Date
- Oct 2008
- Posts
- 48
- Rep Power
- 0
Yes, I did bother to read the tutorial. What I am asking is how to make my program distributable. I specified the classpath for mysql's .jar file, but that's not enough, is it? Because if I give my .jar file for my project to my friend and he tries to run it on his computer, then the classpath is invalid because the mysql connector jar will be non existent on his computer.
So, how do I package everything so that I can let someone download a file and the program works on his computer?
classpaths are paths to jar files on your computer, right? how then, do you make it so that the classpath is accurate on any computer. Do I need to put the mysql .jar file in the user's jre, and then somehow re-write the program's classpath for that location?
People put the jre in different locations on their computer, so how does my program know the classpath to the mysq connector .jar for the computer it is downloaded onto?
I'm sorry for not being clear on my question. thankyou for all the help so far.
- 01-02-2009, 03:47 PM #12
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Package both the mysql jar and your jar into the same directory and reference the mysql jarfile using a relative path (as shown in the tutorial). The MySQL Driver jarfile is freely redistributable. So, what's the problem.
- 01-27-2009, 04:53 AM #13
I see what you are getting at. Been there, done that.
You will have to create some sort of installer that places both your JAR and any other JAR's into a directory.
I provided a batch (cmd) file that sets the classpath and executes the java command. I also found a hack EXE on the Internet that allowed me to create a shortcut for All Users (Windows installation) on the desktop.
Bottom line, I don't know of any elegant way to do this. It may be possible to repackage the MySQL JAR into your JAR, but I think you will run into licensing issues at that point.
- 01-06-2011, 08:52 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Arse-biscuits...just noticed the date on this!
Oopsie.
-
Multiple spam posts deleted and spammers banned. As thread is a spam magnet, I'm locking it.
Similar Threads
-
struts 2 and databases
By rantravee in forum Web FrameworksReplies: 1Last Post: 12-23-2008, 06:59 AM -
password username and databases
By chalo in forum JCreatorReplies: 0Last Post: 12-02-2008, 08:11 AM -
how to use XML databases
By paty in forum XMLReplies: 3Last Post: 08-16-2008, 12:11 AM -
Recommendation about databases
By tommy in forum JDBCReplies: 2Last Post: 07-28-2007, 05:04 AM -
multiple databases
By varunthecool in forum JDBCReplies: 2Last Post: 07-09-2007, 08:06 AM


LinkBack URL
About LinkBacks


Bookmarks