Sunteți pe pagina 1din 44

IBM

Getting Started with Java and AS/400: Java


on AS/400

IBM
Getting Started with Java and AS/400: Java
on AS/400

Copyright International Business Machines Corporation 1997, 1998. All rights reserved.
Note to U.S. Government Users Documentation related to restricted rights Use, duplication or disclosure is
subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.

Contents
Chapter 1. Set up Java on AS/400 . . . . . . . . . . . . . . . . .
AS/400 Developer Kit for Java . . . . . . . . . . . . . . . . . . .
Qshell Interpreter. . . . . . . . . . . . . . . . . . . . . . . .

1
1
1

Chapter 2. Install the licensed programs for Java . . . . . . . . . .


Install a licensed program with the Restore Licensed Program command . . .

3
4

Chapter 3. Set up Remote AWT . . . . . . . . . . . . . . .


Download and install JDK 1.1 on your workstation . . . . . . . .
Set up access to Remote AWT . . . . . . . . . . . . . . .
Map a network drive to your AS/400. . . . . . . . . . . . .
Copy the RAWTGui.zip file to your workstation, using FTP . . . .
Set your environment variables for Remote AWT . . . . . . . . .
Set your environment variables for Remote AWT (Windows NT) . .
Set your PATH and CLASSPATH environment variables (Windows 95
Start Remote AWT . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
or
.

. .
. .
. .
. .
. .
. .
. .
98) .
. .

5
5
6
6
8
10
10
17
21

Chapter 4. Create a Java application for your AS/400


Map a network drive to your AS/400. . . . . . . .
Create a directory on your AS/400 . . . . . . . .
Write a Java application on your workstation . . . .
Name your Java application . . . . . . . . . .
Write your Java program on the AS/400 . . . . . .
Create the Java source code . . . . . . . . .
Copy your Java code to a stream file . . . . . .
Compile your Java application from Qshell Interpreter .
Optimize your Java application. . . . . . . . . .
Run your Java application from Qshell Interpreter . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

23
23
25
26
26
26
27
28
29
30
31

Chapter 5. Whats next? . . .


Java and AS/400 resources . . .
Java education . . . . . . .
AS/400-specific Java education
General Java education . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

33
33
36
36
37

Copyright IBM Corp. 1997, 1998

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

iii

iv

Getting Started with Java and AS/400: Java on AS/400

Chapter 1. Set up Java on AS/400


Its easy to set up Java programming on your AS/400 system. Install AS/400
Developer Kit for Java and Qshell Interpreter licensed programs, and you are ready
to create your first Java application on AS/400.
1. Install the licensed programs for Java.
v AS/400 Developer Kit for Java
v Qshell Interpreter
2. Set up Remote Abstract Window Toolkit (AWT).
v Install JavaSofts Java Development Kit (JDK).
v Set up access to Remote AWT files.
Map a network drive.
Copy the file to your workstation.
v Set your PATH and CLASSPATH environment variables.
v Start Remote AWT.
3. Create a Java application.
v Create a directory for your Java application.
v Write a Java application.
v Compile your Java application.
v Optimize your Java application.
v Run your Java application.
Now that you have run your first Java and AS/400 application, you are probably
wondering what you should do next. Our Whats next section gives you links to a
wide variety of Java and AS/400 resources, so you can keep up-to-date with the
latest technologies and can quickly find the reference material you may need.
[ Legal | AS/400 Glossary ]

AS/400 Developer Kit for Java


Program Java on the AS/400 system with AS/400 Developer Kit for Java. you are
probably familiar with JavaSofts Java Development Kit (JDK), which provides the
Java runtime, core classes, and utilities (such as javac, the Java compiler).
The AS/400 Developer Kit for Java provides the Java platform for AS/400, so if you
want to run Java programs on AS/400, install AS/400 Developer Kit for Java.
Note: For more information about AS/400 Developer Kit for Java, see the AS/400 Developer
Kit for Java product documentation.

[ Legal | AS/400 Glossary ]

Qshell Interpreter
You might have written some Java programs on other platforms, like Windows or
UNIX. If so, you know the standard Java commands such as java, javac, jdb, and
rmic. And, if you have spent any time on an AS/400, you know that AS/400
commands are unique in the computing world.

Copyright IBM Corp. 1997, 1998

If you are starting to wonder how standard Java commands and AS/400 commands
can possibly work together, the answer is Qshell Interpreter. Qshell Interpreter
provides a UNIX-like command environment, or shell (in fact, Qshell closely
resembles the UNIX Korn shell). Install Qshell Interpreter, and you can run the
standard Java commands and AS/400 commands from the same environment.
Qshell Interpreter is not a pre-requisite for running Java on AS/400, but it sure
helps.
Note: For more information about Qshell Interpreter, see the Qshell Interpreter product
documentation.

[ Legal | AS/400 Glossary ]

Getting Started with Java and AS/400: Java on AS/400

Chapter 2. Install the licensed programs for Java


In order to natively program Java on AS/400, you must install AS/400 Developer Kit
for Java. We also suggest that you install Qshell Interpreter, a shell-like
environment that provides support for standard Java commands.
To install these licensed programs, follow these steps:
1. At the AS/400 command prompt, type:
GO LICPGM
Press the Enter key.
The Work with Licensed Programs display appears.
2. Select menu option 11 to install the licensed programs.
3. Scroll through the list by pressing the PageDown key. Find 5769SS1 OS/400 QShell Interpreter, and if it has not been installed, type 1 (Install) in the Option
blank in front of it.
Note: To find out if a licensed program has been installed, press the F11 key on the Install
Licensed Programs display. An installed licensed program displays *COMPATIBLE in the
Installed Status field.
If QShell Interpreter does not appear on the Install Licensed Programs menu at all, you will
need to use the restore licensed programs (RSTLICPGM) method to install the licensed
programs from CD-ROM, disk, or tape.

4. Next, look for 5769JV1. Notice that 5769JV1 has three entries, a base
component (AS/400 Developer Kit for Java) and two options (Java Developer
Kit 1.1.6 and Java Developer Kit 1.1.7) as shown below:
5769JV1
5769JV1
5769JV1

*BASE
1
2

AS/400 Developer Kit for Java


Java Developer Kit 1.1.6
Java Developer Kit 1.1.7

For V4R4, AS/400 Developer Kit for Java provides support for both Java
Development Kit (JDK) 1.1.6 and 1.1.7. You can install both options and
program with either. If your Java program does not specify which JDK version to
use, JDK 1.1.7 is the default. For more information about multiple JDK versions
and AS/400 Developer Kit for Java, see AS/400 Developer Kit for Java product
documentation.
Note:You will probably have to scroll through several pages to find both entries. If one (or
both) of these choices does not appear on the Install Licensed Programs menu, you will
need to use the restore licensed programs (RSTLICPGM) method to install the licensed
programs from CD-ROM, disk, or tape.

5. Press the Enter key. The programs will begin installing.


When the licensed programs are finished installing, the Work with Licensed
Programs display appears again.
[ Legal | AS/400 Glossary ]

Copyright IBM Corp. 1997, 1998

Install a licensed program with the Restore Licensed Program


command
The programs listed in the Install Licensed Programs display are those supported
by the LICPGM installation when your system was new. Occasionally, new
programs become available which are not listed as licensed programs on your
system. If this is the case with the program you want to install, you must use the
Restore Licensed Program (RSTLICPGM) command to install it.
To install a licensed program with the Restore Licensed Program (RSTLICPGM)
command, follow these steps:
1. Put the tape or CD-ROM containing the licensed program in the appropriate
drive.
2. On the AS/400 command line, type:
RSTLICPGM
and press the Enter key.
The Restore Licensed Program (RSTLICPGM) display appears.
3. In the Product field, type the ID number of the licensed program you want to
install.
4. In the Device field, specify your install device.
Note: If you are installing from a tape drive, the device ID is usually in the format TAPXX,
where XX is a number, like 01.

5. We suggest that you keep the default settings for the other parameters in the
Restore Licensed Program display. Press the Enter key.
6. More parameters appear. We suggest that you keep these default settings also.
Press the Enter key. The program will begin installing.
When the licensed program is finished installing, the Restore Licensed Programs
display appears again.
[ Legal | AS/400 Glossary ]

Getting Started with Java and AS/400: Java on AS/400

Chapter 3. Set up Remote AWT


If you are familiar with Java programming, you know that the Abstract Window
Toolkit (AWT) classes provide graphics for Java applications. However, AS/400 does
not currently support Java windowing graphics on locally-attached terminals or
emulator sessions.
AS/400 Developer Kit for Java features Remote AWT capabilities. With Remote
AWT configured on your AS/400 and a client workstation, the AWT graphics of your
AS/400 Java application (running on your AS/400) can be displayed remotely on
your client workstation.
Note: Due to the intensive processing needed to remotely display AWT graphics, processing
time of Java applications using Remote AWT may not be as fast as the same Java
application running on a graphics-enabled platform.

If you do not plan to use AWT graphics in your Java applications, you do not need
to set up Remote AWT.
For this setup, we assume that you have:
v A Win32 workstation (Windows 95, 98, or NT)
v TCP/IP installed and configured on your AS/400 and workstation.
Note:For more information about TCP/IP, see the TCP/IP Fastpath
Setup(http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3A0K00/CCONTENTS
and OS/400 TCP/IP Configuration and Reference(http://publib.boulder.ibm.com:80/cgibin/bookmgr/BOOKS/QB3ANL02/CCONTENTS

manuals.

Follow these steps to set up Remote AWT:


1. Download and install JavaSofts Java Development Kit (JDK) 1.1.
Note: You will need JDK 1.1 installed on your workstation to run Remote AWT. JDK 1.1.6 or
later is recommended. At the time this document was written, Java 2 (JDK 1.2) is not
recommended for use with Remote AWT.

2. Set up access to Remote AWT.


3. Set your PATH and CLASSPATH environment variables.
4. Start Remote AWT.
[ Legal | AS/400 Glossary ]

Download and install JDK 1.1 on your workstation


This section shows how to download and install the most current release of
JavaSofts JDK 1.1 for Win32 workstations.
Note:Instead of downloading the JDK, you might want to purchase the Java JumpStart
CD-ROM, which contains the JDK and many other Java resources. For more information,
see http://java.sun.com:80/javastore/javajumpstart/index.html

1. Download JavaSofts JDK 1.1 from


http://java.sun.com:80/products/jdk/1.1/download-jdk-windows.html
Note: Follow the directions on JavaSofts site to download the JDK. Make sure to carefully
read all licensing agreements.

Copyright IBM Corp. 1997, 1998

2. After you have finished downloading the JDK, follow the To continue
instructions located below the purple download box to install the JDK.
3. Download the JDK documentation from
Make sure you select ZIP
http://java.sun.com:80/products/jdk/1.1/doc.html
file for Windows in the Select Download Format pull-down window.
You need a ZIP file extraction program to install the JDK documentation files. For more
information about ZIP extraction programs, see the JDK documentation installation
instructions (http://java.sun.com:80/products/jdk/1.1/install-docs.html#unbundle).

4. After you have downloaded the JDK documentation ZIP file, follow the To
continue instructions located below the purple download box to install the
documentation.
[ Legal | AS/400 Glossary ]

Set up access to Remote AWT


Remote AWT uses a collection of Java classes which are packaged together in a
file called RAWTGui.zip. To run Remote AWT, your workstations JVM (Java Virtual
Machine), which is provided through the JDK, must be able to access
RAWTGui.zip.
You can choose from two methods of accessing RAWTGui.zip:
v The easiest way to access RAWTGui.zip is to map a network drive to your
AS/400 (using AS/400 Client Access).
v If you do not want to use AS/400 Client Access, copy the RAWTGui.zip file to
your workstation, using FTP (file transfer protocol). The drawback to this method
is that when the AS/400 copy is updated through PTFs (program temporary
fixes), the copy on your workstation will become down-level.
[ Legal | AS/400 Glossary ]

Map a network drive to your AS/400


For these steps, you need AS/400 Client Access for Windows installed on your
AS/400 and on your workstation. For more information on how to install and
configure AS/400 Client Access, see the AS/400 Technical Studio Client Access
Workshop (http://www.as400.ibm.com/tstudio/ca400/caindex.htm).
You must have a connection configured for the AS/400 system before you can map
a network drive.
1. Open Windows Explorer:
a. Right-click on the Start button on your Windows taskbar.
b. Click Explore in the pop-up menu.
2. Select Map Network Drive from the Tools pulldown menu.

Getting Started with Java and AS/400: Java on AS/400

3. Select the drive (for example, X:) you want to connect to your AS/400.
4. Type the path name to the your AS/400 system. For example:
\\MYAS400
where MYAS400 is the name of your AS/400 system.

Chapter 3. Set up Remote AWT

5. If the Reconnect at logon checkbox is empty, click on it.


6. Click OK to finish.
Your mapped drive will appear in the All Folders section of Windows Explorer.
[ Legal | AS/400 Glossary ]

Copy the RAWTGui.zip file to your workstation, using FTP


To provide JavaSofts JDK with access to the Remote AWT classes, copy
RAWTGui.zip from your AS/400 to your workstation using FTP (file transfer
protocol):
1. On your workstation, open an MS-DOS session.
2. Create a directory on your workstation for RAWTGui.zip.
3. At the DOS prompt, type:
ftp myas400
where myas400 is the host name of your AS/400.
Note: If your AS/400 does not have a host name, use your AS/400s IP address instead of a
host name.

A message appears, similar to 'Connected to myas400.company.com.'.


4. You will be prompted for your User name for your AS/400. Type it, and press
the Enter key.
5. You will be prompted for your Password for your AS/400. Type it, and press
the Enter key.

Getting Started with Java and AS/400: Java on AS/400

A message will appear, similar to '230 USER logged on,' where USER is your
AS/400 User ID.
6. Specify binary transfer mode. At the DOS prompt, type:
bin
and press the Enter key.
A message will appear, stating '200 Representation type is binary IMAGE.'
7. Navigate to the jt400 directory on your AS/400. Type:
cd /QIBM/ProdData/Java400/jdkxxx
where xxx is your installed version of AS/400 Developer Kit for Java.
Press the Enter key.
A message will appear, stating '250 '/QIBM/ProdData/Java400/jdkxxx' is
current directory.'
8. Get the RAWTGui.zip file. Type:
mget RAWTGui.zip
and press the Enter key.
A prompt, 'mget RAWTGui.zip?' will appear. Type y and press the Enter key.
Two messages will appear, stating '200 PORT subcommand request
successful' and '150 Retrieving file
/QIBM/ProdData/Java400/jdkxxx/RAWTGui.zip.'
After a few moments, two more messages appear, '250 File transfer
completed successfully' and a message similar to '1238147 bytes received
in 1.65 Seconds (750.39Kbytes/sec).' These messages signal the successful
completion of FTP.
9. End the FTP session. Type:
quit
and press the Enter key.
10. End the MS-DOS session. Type exit and press the Enter key.
[ Legal | AS/400 Glossary ]

Create a directory on your workstation


Follow these steps to create a directory on your workstation.
1. Your MS-DOS prompt probably reads C:\Windows>, where C: is the drive on
which Windows is installed.
If this is the drive on which you would like to have Remote AWT located, type
cd .. and press the Enter key.
If you would like Remote AWT on a different drive (assuming you have one),
type X:, where X: is the letter of the drive you want, and press the Enter key.
2. Create a new directory. Type:
mkdir rawt
where rawt is the name of the directory.
Press the Enter key.
3. Make the new directory your current directory. Type:
cd rawt
and press the Enter key.
The prompt changes from X:\> to X:\rawt> (where X: is the letter of your hard
drive). The directory has been successfully created.

Chapter 3. Set up Remote AWT

Return to the previous page and continue with Step 3.


[ Legal | AS/400 Glossary ]

Set your environment variables for Remote AWT


In order to use Remote AWT on your workstation system, your workstations JVM
(Java Virtual Machine) must know where to locate RAWTGui.zip. You could enter
the location of RAWTGui.zip in the -classpath parameter of the java command, but
this method can be error-prone and tedious.
A better way to pass the location of RAWTGui.zip to your workstations JVM is to
set your workstations CLASSPATH environment variable. The JVM will
automatically search your CLASSPATH statement for the location of RAWTGui.zip.
When using the JDK with other Java packages, you should also set up your PATH
and CLASSPATH environment variables for the JDK.
For Win32 platforms, there are two distinct ways to set environment variables. In
Windows 95 and 98, you can set your PATH and CLASSPATH values by editing
your AUTOEXEC.BAT file. Windows NT offers a dialog window for entering the
values.
To set your programming environment variables, click on your workstations
operating system:
v Windows NT
v Windows 95/98
[ Legal | AS/400 Glossary ]

Set your environment variables for Remote AWT (Windows NT)


Follow these steps to configure your workstation environment variables for Remote
AWT:
1. Open your NT systems environment settings:
a. Double-click the My Computer icon on your desktop.
b. Double-click the Control Panel icon in the My Computer folder.
c. Double-click the System icon in the Control Panel folder.
d. Click the Environment tab in the System Properites window.

10

Getting Started with Java and AS/400: Java on AS/400

2. Update your PATH and CLASSPATH statements for the JDK.


3. Update your CLASSPATH statement for Remote AWT:
v If you have mapped a network drive to your AS/400
v If you have copied RAWTGui.zip to your workstation
4. After you have finished updating your systems environment settings, click the
Apply button. Your new settings will now be in effect.
5. Click the OK button to exit the System Properties window.
[ Legal | AS/400 Glossary ]

Update your PATH and CLASSPATH statements for JDK (Win NT)
Add references to the JDK to your PATH and CLASSPATH statements, located in
the Environment panel of your System Properites window:

Chapter 3. Set up Remote AWT

11

1. In the System Variables window, find the variable Path and click on it. Notice
that the variable and its value appear in the two text fields at the bottom of the
display.

2. At the end of the text in the Value field, add:


;X:\JDK1.1.Y\BIN
where X is the drive on which the JDK is installed, and Y is the version number
of JDK 1.1 that you installed.
This action sets the PATH variable to point to the Java utilities directory. When
you run a Java command, such as java or javac, from an MS-DOS prompt, your
system will automatically locate the utility that the command invokes.
In the example below, JDK 1.1.6 is installed on our C: drive. The brown text
shows what we added to the Path value.

12

Getting Started with Java and AS/400: Java on AS/400

Click the Set button. The Variable and Value text fields clear, and the new
value is added to the system variables.
3. In the System Variables window, look for the ClassPath variable.
If you find the ClassPath variable, click it. At the end of the text in the Value
field, add:
;.;X:\JDK1.1.Y\LIB\classes.zip
where X is the drive on which JDK is installed, and Y is the version number of
JDK 1.1 you installed.
Note: The period (.) in the CLASSPATH statement specifies the current directory. With this
setting, you do not have to specify the full path name (which includes drive and directory
structure) of your Java application to compile or run it.

This action sets your workstations CLASSPATH variable to the JDK class
library, classes.zip. When you compile or run a Java application, the system will
automatically locate classes.zip.
Chapter 3. Set up Remote AWT

13

If you cannot find a ClassPath value, add it.


a. In the Variable field, type:
ClassPath
b. In the Value field, type:
.;X:\JDK1.1.Y\LIB\classes.zip
where X is the drive on which the JDK is installed, and Y is the version
number of JDK 1.1 you have installed.
In the example below, JDK 1.1.6 is installed on our C: drive. The brown text
shows how we created our ClassPath variable and value.

You do not have to click the Set button just yet; we will be adding more to the
CLASSPATH value.

14

Getting Started with Java and AS/400: Java on AS/400

[ Legal | AS/400 Glossary ]

Update your CLASSPATH statement for Remote AWT (Win NT)


Add references to Remote AWT to your CLASSPATH statement, located in the
Environment panel of your System Properites window.
1. Check that the Variable text field reads ClassPath. If it does not, click on
ClassPath in the System Variables window.
2. At the end of the Value field, type:
;X:\QIBM\ProdData\HTTP\Java400\jdkxxx\RAWTGui.zip
where X: is the name of the drive you mapped to your AS/400 and where xxx is
the version of AS/400 Developer Kit for Java you have installed.
In the example below, we mapped our X: drive to our AS/400. The brown text
shows what we added to the CLASSPATH Value field.

Chapter 3. Set up Remote AWT

15

3. Click the Set button. The Variable and the Value fields clear, and the new
values appear in the System Variables window.
[ Legal | AS/400 Glossary ]

Update your CLASSPATH statement for Remote AWT (Win NT)


Add references to Remote AWT to your CLASSPATH statement, located in the
Environment panel of your System Properites window.
1. Check that the Variable text field reads ClassPath. If it does not, click on
ClassPath in the System Variables window.
2. At the end of the Value field, type:
;X:\rawt\RAWTGui.zip
where X: is the drive on which you copied RAWTGui.zip, and rawt is the name
of the directory in which you saved the copy of RAWTGui.zip.
In the example below, we copied RAWTGui.zip to a directory (rawt) on our C:
drive. The brown text shows what we added to the CLASSPATH Value field.

16

Getting Started with Java and AS/400: Java on AS/400

3. Click the Set button. The Variable and the Value fields clear, and the new
values appear in the System Variables window.
[ Legal | AS/400 Glossary ]

Set your PATH and CLASSPATH environment variables (Windows 95 or


98)
Follow these steps to configure your workstation environment variables for Remote
AWT:
1. Open your AUTOEXEC.BAT file for editing. AUTOEXEC.BAT contains your
workstations environment variable settings.
2. Update your PATH and CLASSPATH statements for the JDK.
3. Update your CLASSPATH statement for Remote AWT:
v If you have mapped a network drive to your AS/400
Chapter 3. Set up Remote AWT

17

v If you have copied RAWTGui.zip to your workstation


4. The AUTOEXEC.BAT file sets the environment variables at startup. You can use
one of several methods to reset your environment variables during a session.
We recommend that you reboot your workstation.
[ Legal | AS/400 Glossary ]

Open AUTOEXEC.BAT
Your workstations AUTOEXEC.BAT file contains the programming environment
variables. When you start your workstation, the AUTOEXEC.BAT file sets your
workstations environment.
Follow these steps to open your workstations AUTOEXEC.BAT file.
1. Click on the Start button in the lower left corner of your desktop.
2. Position your mouse over Find.... Select Files or Folders from the Find menu.
3. In the Named field, type autoexec.bat. In the Look in field, select the drive on
which Windows 95 is located. Click on the Find Now button.
4. In the bottom window, right-click on Autoexec.bat.
Note: More that one Autoexec.bat file may be found. More than likely, the first instance is the
one you want. Ignore any occurrance that is located in the backup directory structure.

5. Select Edit from the pop-up menu. If you are prompted to choose a program,
pick Notepad.
[ Legal | AS/400 Glossary ]

Update your PATH and CLASSPATH statements for JDK (Win


95/98)
Follow these steps to add the JDK utilities and core class file to your workstations
programming environment:
1. On a new line in your AUTOEXEC.BAT file, near the beginning of the file, type:
SET JDK=X:\JDK1.1.Y
where X: is the name of the drive on which you have the JDK installed, and Y is
the version of JDK you have installed.
This action sets the variable JDK with the path to your JDK directory. If, in the
future, you install a different JDK, you need only to change this line to change
your PATH and CLASSPATH variables for your new JDK.
2. At the end of the SET PATH line, type:
;%JDK%\BIN
This action sets the PATH variable to point to the Java utilities directory. When
you run a Java command, such as java or javac, from an MS-DOS prompt, your
system will automatically locate the utility that the command invokes.
3. On a different line in your AUTOEXEC.BAT file, type:
SET CLASSPATH=.;%JDK%\lib\classes.zip
Note: The period (.) in the CLASSPATH statement specifies the current directory. With this
setting, you do not have to specify the full path name (which includes drive and directory
structure) of your Java application to compile or run it.

If your AUTOEXEC.BAT file already has a SET CLASSPATH line, add


;%JDK%\lib\classes.zip to the end of the line.

18

Getting Started with Java and AS/400: Java on AS/400

This action sets your workstations CLASSPATH variable to the JDK class
library, classes.zip. When you compile or run a Java application, the system will
automatically locate classes.zip.
The example below shows, in brown, how we modified our AUTOEXEC.BAT file to
include the JDK in our environment variables. The black text shows how our
AUTOEXEC.BAT file originally read. We installed the JDK 1.1.7 on our C: drive.
Your workstations setup may differ, depending on your version of JDK and the drive
on which it is installed.

[ Legal | AS/400 Glossary ]

Update your CLASSPATH statement for Remote AWT (Win 95/98)


Follow these steps to add the RAWTGui.zip file to your workstations programming
environment:
1. On a line in your AUTOEXEC.BAT file, below the SET JDK or SET SWING line,
type:
SET RAWT=X:\QIBM\ProdData\Java400\jdkxxx
where X: is the name of the drive you mapped to your AS/400, and where xxx is
the version of AS/400 Developer Kit for Java you have installed.
This action sets the variable RAWT with the path to the directory which contains
RAWTGui.zip. If, in the future, you decide to move RAWTGui.zip or copy it to
your workstation, you need only to change this line to change your CLASSPATH
variables for Remote AWT.
2. At the end of the SET CLASSPATH line, type:
;%RAWT%\RAWTGui.zip
The example below shows, in brown, how we modified our AUTOEXEC.BAT file to
include Remote AWTs RAWTGui.zip file (which resides on our AS/400) in our
environment variables. We mapped our X: drive to the AS/400 system.

Chapter 3. Set up Remote AWT

19

[ Legal | AS/400 Glossary ]

Update your CLASSPATH statement for Remote AWT (Win 95/98)


Follow these steps to add the Remote AWT class files to your workstations
programming environment:
1. On a new line in your AUTOEXEC.BAT file, below the SET JDK line, type:
SET RAWT=X:\rawt
where X: is the drive and rawt is the directory in which the Remote AWT
RAWTGui.zip file resides.
This action sets the variable RAWT with the path to the directory which contains
RAWTGui.zip. If, in the future, you decide to move RAWTGui.zip or map a
network drive to your AS/400s copy of RAWTGui.zip, you need only to change
this line to change your CLASSPATH variables for Remote AWT.
2. At the end of the SET CLASSPATH line, add:
;%RAWT%\RAWTGui.zip
The example below shows, in brown, how we modified our AUTOEXEC.BAT file to
include Remote AWTs RAWTGui.zip in our environment variables. We copied
RAWTGui.zip to our C: drive.

20

Getting Started with Java and AS/400: Java on AS/400

[ Legal | AS/400 Glossary ]

Start Remote AWT


Before you run a Java application that contains AWT classes on your AS/400
system, you must start Remote AWT on your workstation.
1. Open an MS-DOS prompt.
2. At the prompt, type:
java com.ibm.rawt.server.RAWTPCServer
and press the Enter key.
An Remote-AWT Message window appears, which includes the Remote AWT
version number and your workstations IP address (X.X.X.X).
Your workstation is ready to receive remote graphical user interface components
from your AS/400 system.
Note: For more information about using Remote AWT, see the AS/400 Developer Kit for Java
product documentation

To end Remote AWT on your workstation:


1. Close the Remote-AWT Message window by clicking the X button on the title
bar.
2. At the MS-DOS prompt, type:
exit
and press the Enter key.
[ Legal | AS/400 Glossary ]

Chapter 3. Set up Remote AWT

21

22

Getting Started with Java and AS/400: Java on AS/400

Chapter 4. Create a Java application for your AS/400


You can create a Java application that runs on your AS/400 using any of several
different methods. However, we suggest that you write your Java applications on
your workstation and save them on your AS/400 through a mapped network drive.
Note: If you do not a network drive set up on your workstation, you can use AS/400 Client
Access to map a network drive to your AS/400.

Developing Java applications on your workstation allows you to take advantage of


one of the numerous graphical-based integrated development environment (IDE)
products for Java and other programming tools that are currently on the market.
Follow these steps to create a Java application:
1. Create a directory on your AS/400 for your Java applications.
2. On your workstation, write your Java application and save it on your network
drive.
Note: If you cannot map a network drive to your AS/400, you can write a Java application on
your AS/400 system.

3. Compile your Java application from Qshell Interpreter.


4. Optimize your Java application from Qshell Interpreter.
5. Run your Java application from Qshell Interpreter.
[ Legal | AS/400 Glossary ]

Map a network drive to your AS/400


For these steps, you need AS/400 Client Access for Windows installed on your
AS/400 and on your workstation. For more information on how to install and
configure AS/400 Client Access, see the AS/400 Technical Studio Client Access
Workshop (http://www.as400.ibm.com/tstudio/ca400/caindex.htm).
You must have a connection configured for the AS/400 system before you can map
a network drive.
1. Open Windows Explorer:
a. Right-click on the Start button on your Windows taskbar.
b. Click Explore in the pop-up menu.
2. Select Map Network Drive from the Tools pulldown menu.

Copyright IBM Corp. 1997, 1998

23

3. Select the drive (for example, X:) you want to connect to your AS/400.
4. Type the path name to the your AS/400 system. For example:
\\MYAS400
where MYAS400 is the name of your AS/400 system.

24

Getting Started with Java and AS/400: Java on AS/400

5. If the Reconnect at logon checkbox is empty, click on it.


6. Click OK to finish.
Your mapped drive will appear in the All Folders section of Windows Explorer.
[ Legal | AS/400 Glossary ]

Create a directory on your AS/400


You should create a directory on your AS/400 in which you can save your Java
applications. If you have previously created a directory that you would like to use to
store your Java programs, you can skip these steps.
To create a directory on your AS/400, follow these steps:
1. Signon your AS/400.
2. On the AS/400 command line, type:
CRTDIR DIR(/mydir)
where mydir is the name of the directory you are creating.
Press the Enter key.
A message appears at the bottom of your screen, stating 'Directory created.'
[ Legal | AS/400 Glossary ]

Chapter 4. Create a Java application for your AS/400

25

Write a Java application on your workstation


If you have an integrated development environment (IDE) product installed on your
workstation, use it to code your Java application. See the instructions that came
with your software for information on creating a Java application.
If you do not have an IDE or other programming software, you can always code
your Java application into a any text-based editor (like Windows Notepad).
However you code your application, save it in the directory you created on your
AS/400, which you access through the drive you have mapped to your AS/400
system. Make sure you follow the java naming convention when you choose the
name of your application.
[ Legal | AS/400 Glossary ]

Name your Java application


When naming your Java application, make sure you use the proper naming
conventionname the application with the same name as the class you are
creating.
For example, our Java application listed below creates the class
CommandCallExample.

If you look at the title bar in our example, you will notice that we have named our
application CommandCallExample.java.
[ Legal | AS/400 Glossary ]

Write your Java program on the AS/400


The steps below show how to create a source physical file for your Java program,
how to create the source code for the file, and how to copy the source code to a
stream file so you can compile the program and run it.
1. In order to create the source physical file for your Java program, you need a
library in which to save it.

26

Getting Started with Java and AS/400: Java on AS/400

Note: On AS/400, libraries are not equivalent to directories. The system will not allow you to
save a source physical file in a directory. You must save the file in a library.

Create a library. On the AS/400 command line, type:


CRTLIB LIB(mylib)
where mylib is the name of the library you are creating.
Press the Enter key.
A message appears at the bottom of your display, stating 'Library created.'
2. Create the source physical file for your Java program. Type:
CRTSRCPF FILE(mylib/myfile)
where mylib is the name of the library you created in the previous step and
myfile is the name of the file you are creating.
Note: When choosing a name for the source physical file, you do not have to follow Java file
naming conventions (i.e. naming your Java application after the class that is instantiated).
The file you are creating here acts only as a receptacle for your Java source code. We will
be creating another file for the source code later.

Press the Enter key.


A message appears at the bottom of your screen, stating 'File MYFILE created
in library MYLIB.'
3. Create the source code for the file, using PDM.
4. Copy the source code to a stream file in your directory. Java applications on the
AS/400 must reside in a directory in the Integrated File System. If you copy your
source code to a stream file, you will be able to save it in your directory.
[ Legal | AS/400 Glossary ]

Create the Java source code


Now that you have created the source physical file, you need to add the code. In
this part of the setup, we use PDM (Programming Development Manager) to create
the code and manipulate the file.
1. Start PDM. On the AS/400 command line, type:
STRPDM
and press the Enter key.
The AS/400 Programming Development Manager (PDM) screen appears.
2. The source code for your file is associated with a source member of the file.
Create and edit the source member. Type 3 for Work with members and press
the Enter key.
The Specify Members to Work With display appears.
3. Fill out the display as shown below:
File . . . . . . . . . .
Library . . . . . . . .

myfile
mylib

where myfile is the name of the file you created, and mylib is the name of the
library in which you saved the file.

Chapter 4. Create a Java application for your AS/400

27

Press the Enter key.


4. Press F6 to Create the file member.
Edit the source member. The Start Source Entry Utility (STRSEU) display
appears.
5. Fill out the display as shown below:
Source file .
Library . .
Source member
Source type .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

. > myfile
. > mylib
. myclass
.
TXT

where myfile is the name of your Java program, where mylib is the name of the
library in which you saved it, and myclass is the name of the file member you
are creating.
Note: We suggest you replace myclass with an abbreviated form of your Java class name.

Press the Enter key.


A message appears at the bottom of your display, stating 'Member MYCLASS
added to file mylib/MYCLASS.' The SEU Edit display also reappears.
6. In the Edit display, without pressing the Enter key, type your Java program
code.
Press the Enter key.
The End of data line appears immediately below the line you typed.
Press the F3 key to exit the Edit display.
7. Save the source member. The Exit screen appears. Fill out the display as
shown below:
Change/create member
Member . . . . . .
File . . . . . . .
Library . . . . .
Print member . . . .
Return to editing . .
Go to member list . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

Y
myclass
myfile
mylib
N
N
N

where myclass is the name of your Java program, where myfile is the name of
your physical source file, and where mylib is the name of the library in which
you saved your file.
Press the Enter key.
The Work with Members Using PDM screen appears.
8. Exit PDM by pressing the F3 key twice.
[ Legal | AS/400 Glossary ]

Copy your Java code to a stream file


Before you can compile and run your Java application, you must save it in a
directory in the Integrated File System. To save your Java source code in a
directory, you must copy the code to a stream file:
1. On the AS/400 command line, type:
CPYTOSTMF
and press the F4 key.

28

Getting Started with Java and AS/400: Java on AS/400

The Copy To Stream File (CPYTOSTMF) display appears.


2. Fill out the display as shown below:
From database file member . . .
'/QSYS.LIB/mylib.LIB/myfile.FILE/myclass.MBR'
To stream file . . . . . . . . .
'/mydir/myjavaclass.java'
Stream file option . . . . . . . *NONE
Data conversion options . . . . *AUTO
Database file CCSID . . . . . . *FILE
Stream file code page . . . . . 819
Note: Entering 819 in the Stream file code page field saves the file as ASCII.

where mylib is the name of the library you created, myfile is the name of your
file, and myclass is the name of the source member you created for your source
code.
Replace mydir with the name of the directory in which you want to save your
Java program, and replace myjavaclass with the class name of your Java
application.
Note: See Name your Java application for more information on the Java file naming
convention.

Press the Enter key twice.


A message appears at the bottom of your screen, stating 'Database file
member copied to object.'
[ Legal | AS/400 Glossary ]

Compile your Java application from Qshell Interpreter


To compile and run your Java application on AS/400, use Qshell Interpreter. Qshell
is a UNIX-like command entry environment on AS/400 that allows you to run the
standard Java commands (like javac and java) on your AS/400 system.
Follow these steps to compile your Java application:
1. Make the directory that contains your Java application the current directory.
On the AS/400 command line, type:
CHGCURDIR DIR(/mydir)
where mydir is the name of the directory in which you saved your Java
application.
Press the Enter key.
A message appears at the bottom of your screen, stating 'Current directory
changed.'
2. Enter Qshell Command Entry. On the AS/400 command line, type:
QSH
and press the Enter key.
The QSH Command Entry screen appears.
3. Compile your Java application.
On the Qshell command line, type:
javac myclass.java
Chapter 4. Create a Java application for your AS/400

29

where myclass is the name of your Java application.


Press the Enter key.
After your application is finished compiling, the shell prompt (by default, a $)
appears, signalling that Qshell is ready for another command.
[ Legal | AS/400 Glossary ]

Optimize your Java application


On AS/400, you have the option to optimize your Java application with the
CRTJVAPGM (Create Java application) command.
CRTJVAPGM creates a hidden service program, associated with your class file, that
improves performance. CRTJVAPGM also has an OPTIMIZE parameter that allows
you to select the level of optimization for your service program.
Note: We advise that you run the CRTJVAPGM command on all Java classes, JAR files, and
ZIP files you create.

To optimize your Java application, complete these steps:


1. In the QSH Command Entry screen, enter CL command entry by pressing F21
(Shift and F9).
The command section of the QSH Command Entry screen is replaced with the
Command area.
2. On the Command line, type:
CRTJVAPGM
and press the F4 key.
The Create Java application (CRTJVAPGM) display appears.
3. In the Class file or JAR file field, type:
/mydir/myclass.class
where mydir is the path name of the directory in which your Java application is
saved, and where myclass is the name of your compiled Java application.
Note: See AS/400 Developer Kit for Java documentation for more information about the
parameters on the CRTJVAPGM command.

4. In the Optimization field, type 10.


Note: You can specify an optimization level of up to 40. An optimization level of 40 increases
the execution of the Java application, but it also limits debug capabilities. In the early stages
of developing a Java application we advise you to set your optimization level at 10 so you
can more easily debug your application. See AS/400 Developer Kit for Java documentation
for more information.

5. Press the Enter key.


A message appears, stating that a Java program has been created for your
class.
6. Press F12 to exit CL command entry and return to Qshell.
[ Legal | AS/400 Glossary ]

30

Getting Started with Java and AS/400: Java on AS/400

Run your Java application from Qshell Interpreter


To run your Java application on your AS/400:
1. On the Qshell command line, type:
java myclass
where myclass is the name of your compiled Java application.
Press the Enter key.
2. Your Java application runs. After it is finished, the shell prompt (by default, a $)
appears, signalling that Qshell is ready for another command.
[ Legal | AS/400 Glossary ]

Chapter 4. Create a Java application for your AS/400

31

32

Getting Started with Java and AS/400: Java on AS/400

Chapter 5. Whats next?


You have Java and AS/400 all set up and ready to go. Now what?
Depending on your background, you may need to hone your Java and AS/400
skills. Here are some resources that will be particularly useful to you:
v AS/400 Developer Kit for Java product documentation. This is the online manual
for AS/400 Developer Kit for Java. Learn about the product features and how to
use them.
v AS/400 Developer Kit for Java home page
(http://www.as400.ibm.com/developer/java/devkit.html).

This site lists new

updates to the AS/400 Developer Kit for Java product, so check it often to keep
your software up-to-date.
v Building AS/400 Applications with Java, Version 2
http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/SG242163
(ITSO
Redbook) features projects and code examples using AS/400 Developer Kit for
Java.
v Java for RPG Programmers (http://www.advice.com/ibm/JavaRPG/javarpg.html).
Currently, this is the only AS/400-specific introduction to Java. Even if you
do not know RPG, you will still find the book invaluable for its description of Java
in AS/400 terms.
Be sure to check out our collection of Java and AS/400 resources. We will point you
to books, manuals, websites, magazines, and newsgroups that focus on Java on
AS/400.
[ Legal | AS/400 Glossary ]

Java and AS/400 resources


If you find a helpful Java and AS/400 source on the Internet that is not listed here,
let us know.
v Books (page 33)
v Product documentation (manuals)
v ITSO Redbooks
v Magazines (page 34)
v Internet sites
v Newsgroups, forums, and mailing lists
Note: See our Java education page for information about learning the Java programming
language.

Books
v Java for RPG Programmers (http://www.advice.com/ibm/JavaRPG/javarpg.html)
by Phil Coulthard and George Farr of IBM Toronto. Currently the only
available AS/400-specific guide to Java, this book is extremely helpful for Java
programming on AS/400. Also includes a MINQ Java tutorial CD-ROM,
Introduction to Java Programming using VisualAge for Java Enterprise.

Copyright IBM Corp. 1997, 1998

33

Product documentation (manuals)


v AS/400 Developer Kit for Java
v AS/400 Toolbox for Java
v Qshell Interpreter
ITSO Redbooks (http://www.redbooks.ibm.com)
v Building AS/400 Applicaitons with Java, Version 2
(http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/SG242163)

has

examples of migrating RPG applications to Java. We know you will find it very
useful.
v Building AS/400 Client/Server Applications with Java
(http://publib.boulder.ibm.com/pubs/pdfs/redbooks/sg242152.pdf)
features
projects and code examples using AS/400 Toolbox for Java.
Note:You will need Adobe Acrobat Reader
(http://www.adobe.com/prodindex/acrobat/readstep.html)

to view this document.

v Building AS/400 Internet-Based Applications with Java


(http://publib.boulder.ibm.com/pubs/pdfs/redbooks/sg245337.pdf)

shows how

to design and build AS/400 Internet- or intranet-based Java applications, applets,


and servlets. If you are interested in Java and AS/400s e-business capabilities,
this redbook is for you.
Note:You will need Adobe Acrobat Reader
(http://www.adobe.com/prodindex/acrobat/readstep.html)

Magazines
v NEWS/400 magazine (http://www.news400.com)

to view this document.

offers several good

AS/400 and Java resources in its Java Community


such as The Java Tutorial, Java
(http://www.news400.com/java/index.htm)
articles archive, and a Java newsletter called Java Enterprise Solutions.
v Midrange Computing magazine (http://midrangecomputing.com/mc/).

Since

MC does not publish many of their articles on the Internet, you will probably want
to get a subscription for the good Java articles they frequently feature. You can
also browse through and order back issues for any good articles you might have
missed. MC also publishes the AS/400 NetJava Expert
(http://midrangecomputing.com/ie/)
newsletter.
v Midrange Systems magazine (http://www.midrangesystems.com).

Not only

can you receive a free subscription to Midrange Systems, you can view the
magazine online. Search the archive for Java articles.
Internet sites
v AS/400 and Java home page (http://iws.as400.ibm.com/java/javaframe.htm)
features white papers on AS/400 and Java, providing links to other Java
resources.

34

Getting Started with Java and AS/400: Java on AS/400

v AS/400 Developer Kit for Java home page


(http://www.as400.ibm.com/developer/java/devkit.html).

The home of AS/400

Developer Kit for Java licensed program, this site offers valuable information
about updates for the product.
v AS/400 Toolbox for Java home page
View all sorts of
(http://iws.as400.ibm.com/toolbox/welcome.htm).
information about AS/400 Toolbox for Java, including evaluation downloads,
troubleshooting, and frequently-asked questions.
v Qshell Interpreter home page (http://www.as400.ibm.com/developer/qshell/)
provides references, downloads, and frequently-asked questions about the
Qshell Interpreter licensed program.
v AS/400 Partners in Development Java page
(http://www.as400.ibm.com/developer/java/).

The most comprehensive site

dedicated to Java and AS/400, this home page features articles, demonstrations,
solutions, resources, and information about 'real world' Java implementations by
AS/400 business partners.
v IBM Centre for Java Technology Development
(http://ncc.hursley.ibm.com/javainfo/hurindex.html).

Visit this site from IBM

Hursley for Java news, information, free code downloads, and environment
support for all IBM platforms.
Subtitled 'The Ultimate
v IBM Java home page (http://www.ibm.com/java/).
Resources for Java Developers,' IBMs main Java site offers developer tools and
assistance, technology previews, Java tutorials and education, feature articles,
and JCentral, a search engine tuned to Java on the Internet.
v IBM SanFrancisco home page (http://www.ibm.com/Java/Sanfrancisco/).
IBM SanFrancisco is a Java-based collection of business application components
that allows you to assemble server-side applications from pre-existing parts. The
SanFrancisco home page provides information and resources about the project.
v VisualAge for Java and AS/400 home page
(http://www.software.ibm.com/ad/as400/vajava/).
If you are interested in
what an integrated development environment (IDE) like VisualAge for Java can
do for your Java and AS/400 programming, see this site.
Newsgroups, forums, and mailing lists
Newsgroups
v IBM Hursley AS/400 Java Environment newsgroup
(news:ncc.hursley.ibm.com/ibmpub.java.os400)
v AS/400 newsgroup (news:comp.sys.ibm.as400.misc)
Forums
v IBM Hursley AS/400 Java Environment forum
(http://ncc.hursley.ibm.com/newsgroups/ncc/nccnews?ibmpub.java.os400)
v Midrange Computing Java Programming Discussion forum
(http://www.midrangecomputing.com/forums/)

Chapter 5. Whats next?

35

v News/400 Java forum


(http://www.news400.com/redir/redir.cfm?story=/forums/Index.cfm?CFApp=36)

Mailing lists
v MIDRANGE dot COM JAVA/400 mailing list (http://www.midrange.com/java400l.htm)
[ Legal | AS/400 Glossary ]

Java education
Unlike acquiring other new skills, learning Java does not have to be expensive. You
can find several good Java tutorials on the Internet as well as other educational
materials like books and articles.
Listed below are some of our favorite resources for learning about Java
programming. We have included both 36 and a few 36 links.
See our Java and AS/400 resources for other links that will be helpful in your Java
education.

AS/400-specific Java education


v AS/400 Partners in Developer Java Education
(http://www.as400.ibm.com/developer/java/edu.html)

features

AS/400-specific Java education such as books, Internet-based courses,


classroom training, and workshops.
v Education Roadmap: Programming the AS/400 Java for AS/400
Use this education
(http://iws.as400.ibm.com/INSTITUTE/ct6prjv1.htm)
roadmap from the AS/400 Institute International for determining the prerequisites,
classes, and other resources your need to build your Java for AS/400 knowledge.
v Course Description: Using Java in the AS/400 Environment [S6124]
(http://www.ibmlink.ibm.com/ibmlink?xu=guest&xh=logon&request=education&parms=T_yys6124)
This course is part of the IBM Education and Training AS/400 Curriculum.
(http://www.training.ibm.com/ibmedu/spotlight/as400.html)
v NEWS/400s Java Tutorial (http://www.news400.com/java/javatutorial/)
features a collection of articles written by Java and AS/400 experts Phil Coulthard
and George Farr.
v Java for RPG Programmers (http://www.advice.com/ibm/JavaRPG/javarpg.html)
by Phil Coulthard and George Farr of IBM Toronto. Currently the only
available AS/400-specific guide to Java, this book is extremely helpful for learning
Java programming for AS/400. The book also includes a MINQ Java tutorial
CD-ROM, Introduction to Java Programming using VisualAge for Java Enterprise.

36

Getting Started with Java and AS/400: Java on AS/400

General Java education


v IBM Java Education (http://www.ibm.com/java/education)

includes online

courses, classroom training, white papers, tutorials, articles, books, and FAQs.
lists
v The Java Tutorial (http://java.sun.com/docs/books/tutorial/index.html)
online Java tutorials (basic and advanced Java topics) available from Sun
Microsystems.
[ Legal | AS/400 Glossary ]

Chapter 5. Whats next?

37

IBMR

Printed in U.S.A.

S-ar putea să vă placă și