How will the Easytrive for Linux be called from Java?
There are multiple ways to call Easytrieve for Linux from Java and it's the same way as Java calls other programming language programs.
JNI Approach: If directly interact with Easytrieve's functions is needed, JNI to call native methods implemented in C or C++ that interact with Easytrieve can be used.
This involves writing a Java class with native methods and corresponding C/C++ code to handle the Easytrieve functionality1.
JDBC Approach: If working with databases and need to execute Easytrieve reports, JDBC to connect to the database and execute the reports can be used.
This involves setting up a JDBC driver for your database and writing Java code to execute SQL queries that invoke Easytrieve reports.
Using a Wrapper Library: Create a wrapper library in Java that interacts with Easytrieve.
This involves writing Java code that calls Easytrieve functions through a set of predefined APIs.
Inter-process Communication (IPC): IPC mechanisms like sockets, shared memory, or message queues to communicate between Java and Easytrieve processes.
This method allows Java to send commands to Easytrieve and receive results.
Batch Processing: Set up a batch processing system where Java submits jobs to a scheduler, and those jobs invoke Easytrieve programs.
This is useful for periodic or scheduled tasks.
Web Services: If Easytrieve can be exposed as a web service, Java can interact with it using standard web service protocols like REST or SOAP.
A sample Java program which calls the Easytrieve using Java Runtime exec() method, The ProcessBuilder can also be used as Java Runtime exec is deprecated.
Steps to perfrom:-
----------------
1. Compile the Easytrieve program
eztcom Hello.ezt
ezt -o Hello Hello.pco
2. Compile and execute the Java program
javac sampleJava.java
java sampleJava
Output:-
----------
root:/directory/eztpgm# javac sampleJava.java
root:/directory/eztpgm# java sampleJava
Variant 1 - Exit Code: 0
Hello, world!
Sample Easytrieve Program(Hello.ezt) :
--------------------
* Simple Easytrieve program
JOB INPUT NULL
DISPLAY 'Hello, world!'
STOP
Sample Java Program(sampleJava.java):
-----------------------------
// Java Runtime exec() method
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
//Driver class
public class sampleJava{
//main function
public static void main(String[] args) {
String line;
try {
Process process1 =
Runtime.getRuntime().exec("/directory/eztpgm/Hello");
int exitCode1 = process1.waitFor();
System.out.println("Variant 1 - Exit Code: " + exitCode1);
BufferedReader in = new BufferedReader(new InputStreamReader(process1
.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}