Sharing Your Java Program


Collapse Content

This node will briefly cover simple ways to share and distribute your Java programs.

Sharing the Code

It's a good idea to get feedback on your code, so you need a way to share it. You can just paste snippets of code into an email, but sometimes you'll want to share entire projects.

Sharing the BlueJ Project
If the person you're sharing the code with has BlueJ, its a good idea to just share the entire BlueJ project with them. They can then check out your code, or even use your program with BlueJ as the visual interface!

Method 1 - Email

  1. Go to the folder where your BlueJ Project is located. (If you don't know the location, click on File > Save As, and hopefully it will show you.)
  2. Compress the folder into a zipped file. (See directions for Windows Vista/7, Windows 8, Mac OS X)
  3. Send the zipped file via email or any method.

pigeon-post

Method 2 - Cloud drive

Keep your code in a cloud-synced folder. This way you don't need to worry about losing it. You can then share the folder (or better yet, a copy of it) with other people. (You probably shouldn't have multiple people working on the same project in the same folder simultaneously!)

Free cloud services:

Method 3
Eventually, you should look into sharing your code online on a site like Github. We won't cover that now, but you can check out a Github beginner's guide.

Running your Program outside of BlueJ

You just saw how to share the source code, but eventually you'll want to share the actual program to run it on a computer.

main
The first step is to add a main method to your program. This method should call what's needed to get the program started.

jar
The next step is to compress your program into a jar file. You can do this in BlueJ by clicking on Project > Create Jar File. A box will pop up:

You need to select the Class whose main method should run when the program is executed. (More than one class can have a main method, so your jar needs to declare which one is the main main.)

You can also mark the checkboxes to include the source files and BlueJ files. This is an alternative way to distributing your program instead of zipping it.

Running the program
If your program had a graphic interface, users could open the jar (hopefully) like a normal program. They would need to have the correct version of Java installed on their computer.

You can also run your program from a command line. Navigate to the directory where the jar is located and enter java -jar NameOfJar.jar in the command line. This should uncompress your program and run the main main method.

-jar unzips the jar file, while java calls the JVM to run your program on. If you want to run regular compiled code from the command line, you can just type java NameOfClass in the command line.

You can now email this jar to other people to run on their command line.

Task

  1. Create a main method inside of your Menu class. It should create an instance of Menu and run it.
  2. Create a jar file of your Notebook project using BlueJ.
  3. Run the jar program from your command line.

Comments

  • Hi. My program is doing this:
    http://screencast.com/t/WQ51lIpUlxv

    Explanation: After entering input "quit" the notebook start once again. I must enter again "quite" and after that the program really ends

    cont...
Contact Us
Sign in or email us at [email protected]