× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Having some issues trying to run Java from QSHELL.

Anyone out there that is trying to do Java on the IBM iSeries.

Thomas

mobile 469 693 2533
class HelloWorld
{
public static void main (String args[])
{
System.out.println("Hello World");
}
}

Compile the source file.
Enter the Start Qshell (STRQSH) command to start the Qshell Interpreter.

Use the change directory (cd) command to change the current directory to the
integrated file system directory that contains the HelloWorld.java file.

Enter javac followed by the name of the file as you have it saved on your disk.

For example, enter javac HelloWorld.java.
Set the file authorities on the class file in the integrated file system.


Enter SIGNOFF *LIST.
Then, sign back on.
Enter the Work with Spooled Files (WRKSPLF) command on the IBM i command line.
Go to the bottom of the list.
Find a file named QPJOBLOG.
Press F11.
Verify that the date and time match the date and time when you entered the signoff command.
If the date and time do not match the date and time when you signed off, continue looking through the list of submitted jobs. Try to find a QJVACMDSRV job log with a date and time that matches when you signed off.

Run the class file.

Ensure that your Java classpath is set up correctly.

On the Qshell command line, type java followed by HelloWorld to run your
HelloWorld.class with the Java virtual machine.

For example, enter java HelloWorld. You can also use the

Run Java (RUNJVA) command on your system to run HelloWorld.class:

RUNJVA CLASS(HelloWorld)

"Hello World" prints to your screen if everything was entered correctly.

If running in the Qshell environment, the shell prompt (by default, a $) appears,
indicating that the Qshell is ready for another command.

Press F3 (Exit) or F12 (Disconnect) to return to the command entry display.

===========================================================
CL program I copied from IBM and have started to make changes.

PGM

DCL VAR(&MYCLASS) TYPE(*CHAR) LEN(30) VALUE('HP')
DCL VAR(&JAVA) TYPE(*CHAR) LEN(512)
DCL VAR(&PARM) TYPE(*CHAR) LEN(512)
DCL VAR(&CLASSPATH) TYPE(*CHAR) LEN(512) VALUE('-cp +
/home/BURROWS/JAVAPROGS/CHAP01/BANK')
DCL VAR(&MYPARM1) TYPE(*CHAR) LEN(10) +
VALUE('Winner')
DCL VAR(&MYPARM2) TYPE(*CHAR) LEN(20) VALUE('Hotdog')

DLTF FILE(BURROWS/JAVATST)
MONMSG MSGID(CPF2105)

CRTPF FILE(BURROWS/JAVATST) RCDLEN(132) +
TEXT('JAVA RUN') MAXMBRS(*NOMAX)
OVRDBF FILE(STDOUT) TOFILE(BURROWS/JAVATST)

CHGVAR VAR(&PARM) VALUE(&PARM *bcat &MYPARM1)
CHGVAR VAR(&PARM) VALUE(&PARM *bcat &MYPARM2)
CHGVAR VAR(&JAVA) VALUE('java ' *BCAT &CLASSPATH *BCAT +
&MYCLASS *BCAT &PARM)

QSH CMD(&JAVA)

ENDPGM

==========================================================

The Java™ stdout messages are placed in the output file:

DSPPFM BURROWS/JAVATST

Hello Winner
Hello Hotdog


======================================================

Classpath information

To find any other classes on the system, specify the classpath to search by using the CLASSPATH environment variable or the classpath parameter. The classpath parameter that is used on a tool or command overrides the value that is specified in the CLASSPATH environment variable.

You can work with the CLASSPATH environment variable using the Work with Environment Variable (WRKENVVAR) command. From the WRKENVVAR display, you can add or change the CLASSPATH environment variable. The Add Environment Variable (ADDENVVAR) command and Change Environment Variable (CHGENVVAR) command either add or change the CLASSPATH environment variable.

The value of the CLASSPATH environment variable is a list of path names, separated by colons (:), which are searched to find a particular class. A path name is a sequence of zero or more directory names. These directory names are followed by the name of the directory, the ZIP file, or the JAR file that is to be searched in the integrated file system. The components of the path name are separated by the slash (/) character. Use a period (.) to indicate the current working directory.

You can set the CLASSPATH variable in the Qshell environment by using the export utility that is available using the Qshell Interpreter.

These commands add the CLASSPATH variable to your Qshell environment and set it to the value ".:/myclasses.zip:/Product/classes"

This command sets the CLASSPATH variable in the Qshell environment:


export -s CLASSPATH=.:/myclasses.zip:/Product/classes


This command sets the CLASSPATH variable from the command line:

“ADDENVVAR ENVVAR(CLASSPATH) VALUE(.:/myclasses.zip:/Product/classes)”

The J2SE searches the bootstrap classpath first, then the extension directories,
then the classpath. The search order for J2SE, using the previous example above, is:

The bootstrap classpath, which is in the sun.boot.class.path property,
The extension directories, which is in the java.ext.dirs property,
The current working directory,
The myclasses.zip file that is located in the "root" (/) file system,
The classes directory in the Product directory in the "root" (/) file system.
Some Java tools and commands contain a classpath parameter in which a list of path names
can be specified. The parameter has the same syntax as the CLASSPATH environment variable.
The following list shows some of the tools and commands for which the classpath parameter
can be specified:

java command in Qshell
javac tool
javah tool
javap tool
javadoc tool
rmic tool
Run Java (RUNJVA) command

For more information about these commands, see Java commands and tools. If you use the
classpath parameter with any of these command or tools, it ignores the CLASSPATH environment
variable.

You can override the CLASSPATH environment variable by using the java.class.path property.
You can change the java.class.path property, as well as other properties, by using the
SystemDefault.properties file. The values in the SystemDefault.properties files override the
CLASSPATH environment variable. For information about the SystemDefault.properties file,
see the SystemDefault.properties file.

The -Xbootclasspath option and the java.endorsed.dirs property also affects what directories
the system searches when looking for classes. Using -Xbootclasspath/a:path appends path to
the default bootstrap classpath, /p:path prepends path to the bootstrap classpath,
and :path replaces the bootstrap classpath with path. JAR files located in the directories
specified for the java.endorsed.dirs property are prepended to the bootstrap classpath.

Note: Be careful when you specify -Xbootclasspath because unpredictable results occur when
a system class cannot be found or is incorrectly replaced by a user-defined class.
Therefore, you should allow the system default classpath to be searched before any
user-specified classpath.

See Java system properties for information about how to determine the environment in which
Java programs run.

For more information, see the Program and CL Command APIs or the Integrated file system.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.