I've written a
Java application that uses a MySQL database. When i jar up the whole project it runs the GUI fine but it cant access the database. Im guessing it cant find the MySQL jar file its clearly going to need. Its using "mysql-connector-java-3.1.8-bin.zip".
Someone gave me this solution here:
***************
Create a directory, say it is C:\dev. From here out you will be using the command line.
Within that directory you will have the following:
src\yourPackageName\yourCode.java <-- your source code
classes <-- empty directory for now
lib\mysql-connector-java-3.1.12-bin.jar <--or whatever version you have - make the dir and copy the jar in here
Now, from the C:\dev directory compile your java code with something like
javac -d classes -classpath lib\mysql-connector-java-3.1.12-bin.jar src\yourPackageName\yourCode.java
This should create the file classes\yourPackageName\yourCode.class
Now, cd to classes.
Do a jar -xf ..\lib\mysql-connector-java-3.1.12-bin.jar
Now do a jar -cvf ..\yourJarName.jar *
cd ..
java -cp yourJarName.jar yourPackageName.yourCode will now run your code with MySQL.
***************
Thisworked, and the program runs from the command line BUT i wanted to be able to package up the program into a jar so i could simply install MySQL on a friends computer, then throw the jar onto his desktop so he can just double-click that to run the program. If i try double-click the jar file that was created i get a manifest error, saying it cant load the manifest attribute Main-Class.
Bare in mind the whole idea of this is so i can give this program to a friend that can put the program (the jar) anywhere on his computer and it will run without having to use the command line.
So basically, can someone give me a simple noobs step by step guide on how i can package up my Java application so it will still be able to access the MySQL database, WITHOUT having to use the command line to run it? This seems like a common thing to want to do, to be able to package up your java application after you made it! I refuse to believe nobody has ever made a java app that uses a DB and never wanted to package it up to give to a noob to run it.
Thanks.