CSCI 201 Introduction to Algorithm Design
home | homework index | labs index 
SPRING 2007  

NetBeans Import and Export

This lab will tell you how to ship NetBeans and Java files between computers. This information will be useful when you need to turn in a program.

The goals of this lab are to:

  1. Export a NetBeans project to a single file
  2. Import a NetBeans project stored within a single file
  3. Transfer a single file with FTP

Exporting NetBeans

Opening an old project

Go ahead and start NetBeans and open the GruelWorld project you completed in the Using NetBeans (with Linux) lab. You'll probably see the GruelWorld in the Projects panel when you start NetBeans. If not, you can use the File → Open Project... menu choices to load it.

As you did last week, go over and press the Files tab in the upper-left panel. Now press on those little turnstiles on the left side of the Files panel to expand some of the entries. Try to match the "tree" shown below.
File panel

Cleaning up

Before exporting all these files, it would be nice to clean up the project by removing the build and distribution directories. Cleaning is easy, just return to the Projects panel and right-click on the name of your project. This will bring up a menu from which you can select Clean Project. Job is done. By the way, all of the projects you download from the CSCI 201 web pages have been cleaned.
cleaning a project

If you press on the Files tab, you should see that your project no longer contains the build and dist directories.
a cleaned project

Finding the right directory

Your next step is to put the project directory into a single file, but before you do that you need to figure out just where that project directory is located. Right now you know /home/yourid/csci/201/GruelWorld is your project directory, but suppose you didn't. In that case you need to right-click on the name of your project and then select Properties. This will raise a Project Properties window which will display the name of your Project Folder in the upper-right corner.
Project Properties window

Show your lab instructor a Project Properties window for your project.

One file from many

Now your must pack your project directory into a single file. The common way of doing this is to use a ZIP file. If you are working on a Windows PC and have used zip before you may also want to use it for home to university transfer. However, we're going to use jar, the Java archive program, because it is distributed with the JDK and consequently will work on any system where the JDK is installed.

Alas, jar must be used from the command line. So start up a terminal session and type the following commands to create a jar file called GruelWorld.jar.

[yourid@yourmach currentdir] cd csci/201
[yourid@yourmach 201] jar cfv GruelWorld.jar GruelWorld
[yourid@yourmach 201] ls -l GruelWorld.jar

Your should be about 9,400 bytes in size. This is about one-eighth of the size of the cleaned GruelWorld project directory and one-twelfth the size of the uncleaned project directory.

You may be wondering about that first argument, cfv, to jar. It stands for create file verbose. The verbose tells jar to print lots of messages about its work. The argument following cfv is the file to be created. The remaining arguments are the files and directories that should be placed in the archive.

Show your lab instructor that you have jar'ed your NetBeans project.

Many files from one

Terminate NetBeans and then execute the following command to delete your GruelWorld project.

[yourid@yourmach 201] rm -rf GruelWorld

Yes, it really is gone. But you can restore it with the following command.

[yourid@yourmach 201] jar xfv GruelWorld.jar

By the way, this time the first argument means extract file verbose.

Transferring a file

So now you know how to make and restore projects using jar files. But how do you transfer the jar file to and from your personal system to the UNCA Computer Science computers?

The UNCA Computer Science computers require the use of a secure file transfer program. If your personal system runs Linux, we suggest you just use the command sftp (secure file transfer program). If your personal system runs Windows, we suggest you try the freeware graphical file transfer program WinSCP. Mac OS users will find the command sftp already installed on their systems, but many will prefer the the graphical Fugu created at the University of Michigan.

Since you didn't bring your home system to the lab, we're not going to be able to perform a real file transfer. We suggest you consult our on-line File Transfer tutorial as needed.

Last modified: 01/19/07    

Please Provide Feedback. We will use this information to improve the CSCI 201 Labs.