• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Package Java app that uses MySQL

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to make an executable JAR (one that you can double click to run).

To do that, you need to include a manifest file in your JAR file, that specifies the main class of your application. Basically, you have to create a text file (the manifest file) that contains the following line:

Main-Class: pkgname.MainClassName

(use your package and main class name, ofcourse). When you make the JAR file, use the "m" option and specify the mainfest file:

jar cmf myManifestFile myFile.jar ...

See the documentation of the JAR tool for more information.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Shingsy,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc
 
Shigeru Miyamoto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its 'Shigsy' not 'Shingsy'. Anyway, its short for Shigeru Miayamoto because i thought that was a little long
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shigsy:
Its 'Shigsy' not 'Shingsy'. Anyway, its short for Shigeru Miayamoto because i thought that was a little long



You do know that many programmers are video gamers... What are the odds that a sheriff won't know that it is an obviously fake name?

Henry
 
Shigeru Miyamoto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well 'Henry', if that is your real name, your not a mod so I don't see why you brought it up. Anyway, who is to say your name is not John or Bill.
Can we get this back on topic please, back to the original problem/question?
Thanks.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry brought it up because he cares about the community here. As do many other people, some moderators, some not, including Marc Weber who pointed out the naming policy and asked you to change your name accordingly. This is one of the few rules we have here, and we take it seriously. Some community members may even be less helpful than they might if they see it violated.
 
Shigeru Miyamoto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.... so, back on topic please!
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic