Skip to main content

 
IBM Power Systems software  >  IBM i  > Software  > 

Net.Data for i5/OS

  
Overview News Library Education Support
Java Application Language Environment

Abstract: You can now directly call Java programs from within a Net.Data macro using the Java Application Language Environment (LE).

What is it?
The Java Application LE allows you to call Java programs, enabling easy integration of Java applications with Net.Data.

Why would I want to use it?
Enables you to use features that is provided by a Java program that may not be available by other means. For example, you may have a Java program that can transform a file or spool file to a PDF file.

How do I use it?
Before using the Java Application language environment, complete the following steps:

  1. Install the "System i Developer Kit for Java" licensed program. The "System i Developer Kit for Java" must be installed to run Java applications on the System i.
  2. Set the DTW_JAVA_CLASSPATH path configuration variable in the Net.Data initialization file so Java can find the Java application classes. For example,
    DTW_JAVA_CLASSPATH /directory1/directory2:/myclasses
    

The Java Application LE expects Java programs to contain a method identifier for ' main', the first method that is run in a Java program. When the language environment invokes an application, the application has access to stdin and stdout. There is no form data in stdin because Net.Data has already read the data.

To call a Java program, define a function that uses the Java Application (DTW_JAVAPPS) language environment. Specifying a function name that represents the class name of the Java program. For example:

 

Listing 1. Calls a Java program helloWorld.java
%function(DTW_JAVAPPS) helloWorld() { %}

Pass parameters to a Java program by specifying the parameters to be passed on the function definition. Specify only string parameters that are input-only (IN), or input or output (INOUT).

 

Listing 2. The IN parameter p1 is to be passed on the function call
%function(DTW_JAVAPPS) helloWorld(IN p1) { %}

A complete example is given below. Listing 3 contains the code for the macro echo.nd, which invokes the java program echoString shown in Listing 4. The macro passes two string parameters to the Java language environment. The first string tells the Java program whether to use italic or bold highlighting for the second parameter, a text string, before printing the second parameter to standard output (stdout). Because the program passes "I", for italics, the Web server displays the text string Hello World, in italics, at the browser.

 

Listing 3. The macro echo.nd
%FUNCTION(DTW_JAVAPPS) echoString(textAttribute, text){ %}
%HTML(runjava){
@echoString("I","Hello World")
%}    

 

Listing 4. The Java program echoString.class
class echoString {
public static void main (String args[]) {
if (args[0].equals("I"))
System.out.println("" + args[1] + "");
else
System.out.println("" + args[1] + "");
}
}

Java programs that are part of a package are usually invoked with periods in the class corresponding to the Java program. However, Net.Data did not allow periods in function names. Now, you can specify and call a function that has a function name that includes periods. For example:

Listing 5. Calling packaged Java programs

%FUNCTION(DTW_JAVAPPS) mypackage.HelloWorld() { %}
%HTML {
@mypackage.HelloWorld()
%}

 

Availability
V4R4 and subsequent releases. Ensure you have the latest Net.Data PTF.