Java Interface introduced in Lycia allows you to utilize your Java code in your 4GL programs.
Before you will be able to use Java code in your 4GL programs, you need to install the JRE and to specify the environment variables pointing to the Java files you will be using and to the necessary libraries.
To be able to import and use Java classes you need to install Java Runtime Environment (JRE) of version 6 or above. The JRE contains all the functionality necessary to use the Java interface, because Java interface utilizes the already compiled .class files or Java packages containing .class files. The creation and compilation of Java classes that can be performed by JDK as well as Java language syntax are outside of the scope of this manual.
If you use Lycia as is, without any custom configurations, then you do not need to configure Java as well – Lycia will use your default system Java installation.
If you want to use a non-default Java installation, you must configure Lycia and specify the path to the necessary Java libraries – libjvm.so (or libjvm.dylib) on Unix/Linux or jvm.dll on Windows.
Paths to Java libraries can be specified in these custom configuration files:
To specify the path to Java libraries, you must add one of these environment variables to the necessary configuration file:
PATH: for example, PATH=$PATH;C:\Program Files\Java\jre1.8.0_211\bin\server
LD_LIBRARY_PATH: for example, LD_LIBRARY_PATH = $JRE_HOME/lib/amd64/server/
DYLD_LIBRARY_PATH: for example, DYLD_LIBRARY_PATH = /System/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Libraries
To learn where exactly Java libraries are located on your development station, you can use these commands:
On Windows,
On Unix/Linux (depending on the distribution):
or
All the Java resources which contain the classes you intend to use in Java interface should be specified in the CLASSPATH environment variable. This variable should point at the directory or directories where compiled .class files or Java packages containing .class files are located.
If you want to use a custom class you should create a .java file with this class, compile it into the .class file and set the path to it in CLASSPATH.
If you only work with the Java classes included into Java Class Library which is shipped together with the JRE, you don't need to specify the path to these classes in CLASSPATH, they will be found automatically.
Java Virtual Machine is used to run java byte code integrated into 4GL. A JVM is distributed along with a set of standard class libraries that implement the Java application programming interface (API). Appropriate APIs bundled together form the Java Runtime Environment (JRE), so you need a JRE installed to be able to use Java interface.
If you compile your program in LyciaStudio and this program includes some Java classes references, LyciaStudio will look up the referenced classes in the Java packages located in the directories specified in CLASSPATH in the libraries shipped together with the JRE.
However, if you compile an application containing Java classes references in command line, you can instruct qfgl and qrun to pass command line options to the Java Virtual Machine during initialization. This is achieved using the --java-option command line argument.
For example, you can pass the Java class path qfgl as follows:
$ qfgl --java-option=-Djava.class.path=<ClassPath> myprog.4gl
You only need either the CLASSPATH environment variable set or the --java-option command line argument added to compile the application successfully. You do not need to set both. You also do not need to set any of them, if you use the classes from the standard Java Class Library.