38-jar-files

38-jar-files - Brandon Burr Handout#38 CS 106A Sending Your Programs to Mom A.K.A Packaging Your Program Into a Distributable JAR File and Putting

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Brandon Burr Handout #38 CS 106A Sending Your Programs to Mom A.K.A. Packaging Your Program Into a Distributable JAR File and Putting Your Programs on the Web Now that you’ve written all these wonderful programs, wouldn’t it be great if you could package them up and send them to your mom so that she could see what you’ve done? Because we here in 106A feel that no mom should be spared the joy of sitting through a simplified version of a game she’s undoubtedly played a million times before, here’s a short guide to making an executable JAR file in Eclipse! And for those internet junkies, stay tuned. At the end of this handout we’ll also show you how to put your programs up the web for the whole world to play! Making an executable JAR file Eclipse makes it easy to package your code up into a JAR file that you can double-click to run. You’ll have to do a little more work if your program uses other files (images, sounds, or data files), but it’s not too hard. Follow the steps described below. Step 1, Adding a main() method In CS106A all of our programs have used the ACM libraries. Consequently, we’ve used the public void run() method as the starting point for everything we’ve written. Standard Java doesn’t actually work this way, and we modified Eclipse to get it to work this way, to keep things simple early on in the course. But in reality, a Java program needs to start at a particular method in a class, the public static void main(String args) method. If your program uses the ACM libraries, you’ll need to edit your code to have a main() . You can do this easily by simply adding the following code to the class that has the public void run() , substituting the name of that class for ‘Yahtzee’ below. public static void main(String args) { new Yahtzee().start(args); } If you remember at the beginning of the quarter, we said that you needed the special Stanford version of Eclipse to run your programs, this is because of the edit (mentioned above) that we made to Eclipse. But if you add this main() method your program should run fine in any Java compiler....
View Full Document

This note was uploaded on 10/14/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 5

38-jar-files - Brandon Burr Handout#38 CS 106A Sending Your Programs to Mom A.K.A Packaging Your Program Into a Distributable JAR File and Putting

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online