Tutorial: Running an iSeries Java program remotely

This tutorial guides you through creating a Java project, exporting it to an iSeries server and running it remotely, using the iSeries Java development tools.

To complete this tutorial you must have a profile on an iSeries host, and you must create a directory in the iSeries integrated file system (IFS).

You can run an iSeries Java program remotely in the iSeries Java Transform and Run View or in the iSeries launch configuration. The programs that you run must be applications (classes that contain a main method). Before you can run an iSeries Java program, you must export Java class files to your IFS directory.

Creating a Java project and writing a "Hello world" program:

  1. Open a Java Perspective: Click Window > Open Perspective > Java.
  2. Create a Java project called TutorialProject:
    1. From the main menu click File > New > Project. The New Project wizard opens.
    2. Click Java > Java Project > Next.
    3. For Project name type TutorialProject.
    4. Click Finish. An empty Java project named TutorialProject appears in the left pane (Package Explorer view).
  3. Add a package and a Hello.java class to the project:
    1. In the left pane, right-click on TutorialProject and select New > Package .
    2. In the Name field, type tutorialPackage.
    3. Click Finish. The package appears in the left pane.
    4. Right-click on tutorialPackage and select New > Class.
    5. In the Name field, type Hello.
    6. Under Which method stubs would you like to create? , select the check box next to public static void main(String[] args).
    7. Click Finish. Your source code for Hello.java appears in the editor.
  4. Complete the "Hello world" program:
    1. You should see the following code:
          public class Hello {
              public static void main(String[] args) {
              }
          }
    2. Before the two closing brackets, insert the line:
         System.out.println ("Hello world!");
      Now the code for the whole class looks like this:
          
      		public class Hello { 
      			public static void main(String[] args) {
      			System.out.println ("Hello world!"); 
             }
          }
    3. Click Ctrl + S to save your code. Your class is automatically compiled and a Hello.class file appears in TutorialProject.

Exporting your Java project to a remote file system

  1. In the Package Explorer view, click the project to select it.
  2. From the workbench menu bar, select File > Export. The Export wizard opens.
  3. Select Remote file system. Click Next. The Remote file system page opens.
  4. Notice that in the left pane your project is already selected. In the right pane a .project and a .classpath file are selected. Expand the project name and click tutorialPackage. The .java file and the .class file are also selected.
  5. Beside the Folder field, click Browse and navigate to your home directory on the iSeries host (in the IFS).
  6. Click Create directory structure which replicates the workspace folder structure in the remote system.
  7. Click Finish.
The project is exported to the remote system; a copy remains in the workspace.

Running your Java program remotely

You can now run your iSeries Java program remotely in both the iSeries Java Transform and Run view and the iSeries launch configuration.
  • In the launch configuration you run a program which you store locally in the workspace but also have exported to an iSeries server.
  • In the Transform and Run view you call the program from the server; the view is independent of the local workspace.

To run your Java program in the iSeries Java Transform and Run view:

  1. Make sure you are in the Java Perspective.
  2. Switch to the iSeries Java Transform and Run view:
    1. Click the down arrow next to the run icon Run icon (circle containing triangle) on the workbench menu bar.
    2. Select Run As > Remote Java Application in iSeries view.
  3. To populate the Working Folder field, click Browse and again navigate to your home directory on the iSeries host. Select TutorialProject.
  4. Click the Run remotely tab.
  5. In the Class field, enter tutorialPackage.Hello.
  6. Click Run to start the remote invocation. The Console out field displays "Hello world!"
The Java application runs on the iSeries server.

To run your Java program using the iSeries launch configuration:

  1. Make sure you are still in the Java Perspective.
  2. Click TutorialProject to select it.
  3. Click the down arrow next to the run icon Run icon (circle containing triangle) on the workbench menu bar.
  4. Select Run. The Launch Configurations dialog opens.
  5. Click Java application in iSeries server. Click New.
  6. Optional: Give the configuration a name, such as "Hello."
  7. Under the Main tab, fill in the name of the project ( TutorialProject) and the name of the package and Main class ( tutorialPackage.Hello). Beside Remote iSeries Working folder, click Browse and navigate to the project in your home directory on the iSeries server.
  8. Click Run to run the program. The Console displays "Hello world!"
The configuration now appears as a shortcut in the down-arrow menu.

Note:

You can debug your application from the iSeries launch configuration. The steps are similar to those above, but you start by clicking the down arrow next to the debug icon Debug icon (picture of bug and arrow) rather than the run icon. Before you can debug an iSeries Java application, you must export your class files to an IFS directory. You can debug your Java application directly from the source in your workspace.