Compiling and testing WebSphere MQ base Java programs

 


Overview

Before compiling WebSphere MQ base Java programs, ensure that your WebSphere MQ classes for Java installation directory is in your CLASSPATH environment variable.

To compile a class called MyClass.java, use the command:

javac MyClass.java

 

Running WebSphere MQ base Java applets

If you write an applet (subclass of java.applet.Applet), you must create an HTML file referencing your class before you can run it. A sample HTML file might look as follows:

<html>
<body>
<applet code="MyClass.class" width=200 height=400>
</applet>
</body>
</html>

Run your applet either by loading this HTML file into a Java-enabled Web browser, or by using the appletviewer that comes with the JDK .

To use the applet viewer, enter the command:

appletviewer myclass.html

 

Running WebSphere MQ base Java applications

If you write an application (a class that contains a main() method), using either the client or the bindings mode, run your program using the Java interpreter. Use the command:

java MyClass

Note:
The .class extension is omitted from the class name.

 

Tracing WebSphere MQ base Java programs

WebSphere MQ base Java includes a trace facility, which you can use to produce diagnostic messages if you suspect that there might be a problem with the code. (You normally need to use this facility only at the request of IBM service.)

Tracing is controlled by the enableTracing and disableTracing methods of the MQEnvironment class. For example:

MQEnvironment.enableTracing(2);   // trace at level 2
 ...                              // these commands will be traced
MQEnvironment.disableTracing();   // turn tracing off again

The trace is written to the Java console (System.err).

If your program is an application, or if you run it from your local disk using the appletviewer command, you can also redirect the trace output to a file of your choice. The following code fragment shows an example of how to redirect the trace output to a file called myapp.trc:

import java.io.*;
 
try {
  FileOutputStream
  traceFile = new FileOutputStream("myapp.trc");
  MQEnvironment.enableTracing(2,traceFile);
}
catch  IOException(ex) {
  // couldn't open the file,
  // trace to System.err instead
  MQEnvironment.enableTracing(2);
}

There are five different levels of tracing:

  1. Provides entry, exit, and exception tracing

  2. Provides parameter information in addition to 1

  3. Provides transmitted and received WebSphere MQ headers and data blocks in addition to 2

  4. Provides transmitted and received user message data in addition to 3

  5. Provides tracing of methods in the Java Virtual Machine in addition to 4

To trace methods in the Java Virtual Machine with trace level 5:

  • For an application, run it by issuing the command java_g (instead of java)

  • For an applet, run it by issuing the command appletviewer_g (instead of appletviewer)

Note:
java_g is not supported on OS/400, but similar function is provided by using OPTION(*VERBOSE) on the RUNJVA command.

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.