Java integration

Java Interface introduced in Lycia allows you to utilize your Java code in your 4GL programs.

Adjusting Java environment

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.

Installing Java

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.

Setting the dynamic linker

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

Your exact location of jvm.dll, libjvm.so, and/or libjvm.dylib may differ from the above examples.

To learn where exactly Java libraries are located on your development station, you can use these commands:

On Windows,

for %i in (java.exe) do @echo. %~$PATH:i

On Unix/Linux (depending on the distribution):

$(dirname $(dirname $(readlink -f `which java`)))/jre/lib/amd64/server

or

$(dirname $(dirname $(readlink -f `which java`)))/lib/amd64/server

Locating Java resources

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.

You should add CLASSPATH to the system environment variables rather that to the user variables. While Lycia runs as local user and can utilize the user variables (which will allow you to compile your program), GUI clients run as administrator and if CLASSPATH is set only for a user, a runtime error will occur.

Passing options to JVM

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

-cp and -classpath options supported by the Java runtime are not recognized when the Java Virtual Machine is initialized via the Java Native Interface; -Djava.class.path must be used instead.

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.

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.