In this lab, you will deploy a lab project and run it outside of Eclipse.
In this part, you will export one of your lab projects to the file system and then execute it from a command line.
The project you will deploy will be based on the Lab08 project, which used arrays and collections. In particular, you will test the part4 program that displayed distances between cities.
Find the IowaDistanceMatrix class in the Lab08/part4 project and examine the code so you can remember how it works.
Note: If you did not finish this lab, ask your instructor how to obtain the solution.
Create a new project named Lab12 and copy the Lab08/part4 package to the new project's src folder.
Open the copied IowaDistanceMatrix.java class into the editor.
Modify the main method so that it accepts the names of the two cities as command-line arguments and then calls the distance method.
If the main method is not passed two arguments, the program should display an appropriate message and exit.
Here is some code to get you started:
if (args.length == 2)
{
String city1 = args[0];
String city2 = args[1];
. . .
}
else
System.out.println ("Two cities required");
Run the program as a Java application in Eclipse to test your argument-count checking -- you should see your error message in the Eclipse console.
In the Package Explorer, right-click on IowaDistanceMatrix.java then choose Run As - Run Configurations and press the Arguments tab, then set the Program arguments to "Des Moines" Keokuk (the double quotes are required).
Press the Run button -- you should see the distance "202" in the Eclipse console.
Now let's export from Eclipse to the file system. Follow these steps:
In the Package Explorer, right-click on the Lab12 project and choose Export....
On the first wizard page, choose General - File System, then press Next.
On the next wizard page, first uncheck the Lab12 entry, then expand it.
Expand the bin entry, then put a checkmark on the part4 entry. Then click on the part4 entry to highlight it, and note that IowaDistanceMatrix.class shows up in the right column.
For the To directory, enter {Lab Installation Directory}/deploy. On Windows XP, this directory is:
c:\javaclass\deploy
On Windows Vista or later, the directory is:
c:\Users\username\javaclass\deploy
Make sure that your dialog matches the screen shot in Figure 1, then press Finish. When asked to create the target directory, answer Yes.

From the Windows Start menu, choose Run and enter cmd.
In the resulting command-prompt window, change to the deployment directory and examine the files. On Windows XP:
cd \javaclass\deploy
dir
dir part4
On Windows Vista or later:
cd \Users\username\javaclass\deploy
dir
dir part4
You should see IowaDistanceMatrix.class in the part4 directory.
To run the program, enter:
java part4.IowaDistanceMatrix
You should see your argument-count error message.
Try again:
java part4.IowaDistanceMatrix "Des Moines" Keokuk
You should see the distance between the two cities.
Here's what you should've learned from this part:
In this part, you will deploy a program to JAR file, which is useful if the program comprises many .class files.
In this part, you will deploy your Lab09 project, which uses inheritance and polymorphism. This project used several classes, resulting in several .class files. While you could deploy the .class files to the file system like you did in the last part, it's easier to manage larger projects using a single JAR file.
Edit the Lab09/test/TestInventory class and re-acquaint yourself with it. Run this class as a Java application within Eclipse and note its console output.
Note: If you didn't finish this project, ask your instructor how to obtain the solution.
To export to a JAR, follow these steps:
Right-click on the Lab09 and choose Export....
On the first wizard page, choose Java - JAR File, then press Next.
On the next wizard page, ensure that the Export java source files and resources checkbox is NOT selected.
For the JAR File destination, browse or enter to {Lab Installation Directory}/deploy. On Windows XP:
c:\javaclass\deploy\lab09.jar
On Windows Vista or later:
c:\Users\username\javaclass\deploy\lab09.jar
The wizard should look like Figure 2. Press Finish to export to the JAR.

Go to the command-prompt window (if you closed it, repeat the steps in the last part to open a new one). In the command prompt, run the program, specifying that the JAR file is in the JVM's CLASSPATH:
java -cp lab09.jar test.TestInventory
You should see your program's output.
Here's what you should've learned from this part: