Packaging Your Program into a Distributable JAR File

Similar documents
- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

1. Go to the URL Click on JDK download option

Getting Started with Eclipse/Java

Eclipse Environment Setup

Lecture (01) Getting started. Dr. Ahmed ElShafee

SIS offline. Getting Started

Mehran Sahami Handout #5 CS 106A September 26, 2018 Downloading Eclipse

Summer Assignment for AP Computer Science. Room 302

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

RTMS - Software Setup

1.00/1.001 HowTo: Install Eclipse

Mehran Sahami Handout #5 CS 106A September 27, 2017 Downloading Eclipse

Using Karel with Eclipse

POOSL IDE Installation Manual

Finally, you get a very easy, user-friendly tool to create and run Java applets. This is what you will use for the rest of the labs.

What is Eclipse? A free copy can be downloaded at:

CS 170 Java Tools. Step 1: Got Java?

Configure Eclipse with Selenium Webdriver

1.00 Lecture 2. What s an IDE?

Using Eclipse for C Programming

Using Eclipse and Karel

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

CSCI 201 Lab 1 Environment Setup

CS 170 Java Tools. Step 1: Got Java?

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

CreatingAlgPlugin. 1 of 5 07/23/ :11 PM. Creating an Algorithm Plugin

CHAPTER 6. Java Project Configuration

Crawling Assignment. Introduction to Information Retrieval CS 150 Donald J. Patterson

Hadoop Tutorial. General Instructions

Customizing DAZ Studio

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

Java using LEGO Mindstorms and LeJOS. University of Idaho

How to make a Work Profile for Windows 10

02/03/15. Compile, execute, debugging THE ECLIPSE PLATFORM. Blanks'distribu.on' Ques+ons'with'no'answer' 10" 9" 8" No."of"students"vs."no.

The Java Main Method

DropSend Getting Started Guide

Laboratory 1: Eclipse and Karel the Robot

CS 106A, Lecture 25 Life After CS 106A, Part 1

Adding Existing Source Code in NetBeans CS288, Autumn 2005 Lab 002

Introduction to Computation and Problem Solving

CONSUMING CUBEMASTER CALCULATION WEB SERVICE FROM JAVA Logen Solutions

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

Running Java Programs

Note, you must have Java installed on your computer in order to use Exactly. Download Java here: Installing Exactly

What s NetBeans? Like Eclipse:

Setting Up the Development Environment

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

form layout - we will demonstrate how to add your own custom form extensions in to form layout

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Task-Oriented Solutions to Over 175 Common Problems. Covers. Eclipse 3.0. Eclipse CookbookTM. Steve Holzner

Basics of Adobe Premiere

COMP220/285 Lab sessions 1-3

1. The Apache Derby database

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

Mehran Sahami Handout #7 CS 106A September 24, 2014

Developing Android applications in Windows

COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE. Instructor: Prasun Dewan (FB 150,

be able to read, understand, and modify a program written by someone else utilize the Java Swing classes to implement a GUI

Exporting a Course. This tutorial will explain how to export a course in Blackboard and the difference between exporting and archiving.

COMP 215: INTRO TO PROGRAM DESIGN. Prof. Chris Jermaine Chris Prof. Chris Dr. Chris

Lab #1: A Quick Introduction to the Eclipse IDE

TURNING IN ASSIGNMENTS

CREATING CUSTOMER MAILING LABELS

If you don t have the JDK, you will need to install it. 1. Go to

TekTalk Word 2007 Notes

Software AG Designer. Installing Plug-ins and Fixes Offline

The ImageJ Eclipse Howto

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Computer Science 62 Lab 8

CMPSCI 187 / Spring 2015 Sorting Kata

Installing Eclipse (C++/Java)

Javac and Eclipse tutorial

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

Storing and Managing Code with CVS

Making Apps With JavaFX COMP110 - Lecture 23

Configuring GNS3 for CCNA Security Exam (for Windows) Software Requirements to Run GNS3

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

6 Starting in Eclipse

Do this by creating on the m: drive (Accessed via start menu link Computer [The m: drive has your login id as name]) the subdirectory CI101.

For Volunteers An Elvanto Guide

Cross-Domain Development Kit XDK110 Platform for Application Development

Welcome to CSSE 220. We are excited that you are here:

JPA - INSTALLATION. Java version "1.7.0_60" Java TM SE Run Time Environment build b19

S8352: Java From the Very Beginning Part I - Exercises

Manual Eclipse CDT Mac OS Snow Leopard

Getting Started with the Bullhorn SOAP API and Java

Java with Eclipse: Setup & Getting Started

Installing Design Room ONE

1. The Apache Derby database

IBM WebSphere Java Batch Lab

UNic Eclipse Mini Tutorial (Updated 06/09/2012) Prepared by Harald Gjermundrod

Getting Started with Eclipse for Java

Your . A setup guide. Last updated March 7, Kingsford Avenue, Glasgow G44 3EU

The following steps will create an Eclipse project containing source code for Problem Set 1:

Karlen Communications Word 2007 Settings. Karen McCall, M.Ed.

RadBlue s S2S Quick Start Package (RQS) Developer s Guide. Version 0.1

Setting up Outlook Express to access your boxes

Transcription:

Colin Kincaid Handout #5 CS 106A August 8, 2018 Packaging Your Program into a Distributable JAR File Based on a handout by Eric Roberts and Brandon Burr 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 friends and family so that they could see what you ve done? JAR files, or Java ARchive files, let you do just that. Here s a short guide to making an executable JAR file in Eclipse! Step 1: Adding a main method Our programs that have used the ACM libraries and CS 106A Eclipse have started running via the public void run() method. We changed Eclipse to allow this, to make things easier for you. But in reality, a Java program needs to start at a particular method in a class, the public static void main(string[] args) method. In order to export your program you ll need to edit your code to explicitly have main(). Then your program should run fine in any Java compiler. You can do this by adding the following code in the class that has public void run(), substituting the name of that class for MyClass below. public static void main(string[] args) { (new MyClass()).start(args); } Step 2: Exporting a JAR File Now that we have a normal running Java program, let s package it up into a JAR file. A JAR file is simple a Java ARchive a file that contains a set of Java class files as well as potentially other files that will be used by the program. As part of this, we need to export both a JAR file and a manifest file. The manifest file allows you to specify things like which is the main class to run when the JAR file is double-clicked, or what the external libraries are, or even security information about the JAR file. (If you aren t using other JAR files, you don t need to use the manifest file.) Follow the steps on the following pages to export your program.

2 1. Click the project folder in the Eclipse sidebar that you want to export, and click File -> Export The following window should appear: 2. Expand the Java folder, and select JAR File. Then click Next. 3. You should see the JAR export window. Expand the project folder on the left and make sure that the default package is selected, and select the destination of where you want to save the JAR file using the Browse... button. Then hit Next.

3 4. Click Next again on the following screen. 5. Now you will come to the final screen: We need to input the name of the class to run when the JAR file is launched. Near the bottom of the window, select the Main class using the Browse... button. The main class (MyClass, in this case) should show up in the list if you correctly added the main() method as described previously. If you are exporting a project without any other JAR files (e.g. without the ACM libraries), then just click Finish. You re done! Go ahead and send the JAR to family and friends. Just remember that they need to have Java installed too; see the end of this handout for more information. If you are exporting a project with other JAR files (e.g., with the ACM libraries), continue on to the next step.

4 6. Now we need to create a manifest file. To do this, we will go through this exporting process twice. The first time is to generate a manifest file, and the second time is to use that file when exporting our program. So, from here, make sure the Generate the manifest file radio button near the top of the window is selected, and that check box for Save the manifest in the workspace' is checked. Click the Browse button associated with the Manifest file text box to select the destination of the manifest file. 7. In the window that appears, click the MyProject folder (or whatever your project is named), and then in the text box type in the name manifest and click OK to finish. The Manifest file path should now appear as something like /MyProject/manifest. Click the 'Finish' button.

5 8. Now you should see the manifest file show up in the Eclipse sidebar. Double-click it to open it. You need to edit the manifest file to add the line "Class-Path: " followed by the names of all the JAR files that this program uses, separated by spaces. In this case, that would include spl.jar, since that contains the ACM libraries, as well as the JAR file you just exported (in this case called MyJar.jar). When you re done the manifest file will look something like this: Make sure to save the updated manifest file. Now that we have this manifest file, repeat the entire above process of exporting a JAR file (i.e., click on your project name, pick Export... from the file menu, select the JAR file option for exporting, etc.). However, this time you will do something different when you get to the last window, as explained in the next step.

6 9. When you get to the last screen, you do not need to generate a manifest file or specify the Main class. Instead, just make sure to click the radio button for Use existing manifest from workspace. Now, hit the Finish button. Eclipse will use the manifest file we just created previously to make our JAR file. If it asks you to overwrite the old JAR file, just say Yes. 10. Now you have your JAR file containing your project code, but unfortunately you can t simply send it to your friends. This JAR doesn t contain the code in the other JAR files it relies on (e.g. spl.jar), nor does it contain any data files your program might use (text files with data, or even sounds or images). What you ll want to do is create a new folder (on your computer, not in Eclipse), place your exported JAR file in it, along with any other JAR files your program uses (like spl.jar and any other the ones you added to the manifest file) and data files you use. Make sure to put your data files in a folder called res if your code expects that. Note that you do not need to put spl.jar in a lib folder; put it in the same folder as your exported JAR file. Once you have all of these files in a single folder, you should be able to just double-click your JAR file, and have it run your application. You will need to distribute this entire folder to anyone that you want to share your program with. Usually the easiest way is to just zip the folder up into a single file, and then email that. Then, the recipient can unzip the folder and double-click the enclosed JAR file to run your program!

7 A final note regarding the Java Runtime Environment (JRE) Anyone who has your JAR files does not need Eclipse to run it, but they will need to have the Java Runtime Environment (JRE) installed on their computer. In fact, you may have installed the JRE on your own computer at the beginning of CS106A so that you could work with Java. Some, but not all, computers come pre-installed with the JRE. We just wanted to point this out in case you pass along the JAR files for your program to someone who may not have the JRE installed and was having problems trying to run your program as a result. Pass along the instructions on the CS 106A website to install the JRE.