Installing and distributing
Install the package with RingPM, build it for Linux and macOS, and give a Ring program that uses Java to people who have no Ring and no Java.
Install#
ringpm install ringjava from ringpackagesThe package is one zip file (extensions/ringjava.zip): RingPM copies it and setup.ring extracts it into the Ring folder. It brings ring_java.dll, ringjava.jar, the library, the generated Ring classes of 181 Java packages, the samples, the tools and a ring2exe library file (tools/ring2exe/libs/java.ring). ringpm remove ringjava runs uninstall.ring, which deletes exactly the files that were extracted (the list is extensions/ringjava/package-files.txt).
You need a JDK 17 or later: see Getting started.
Linux and macOS#
The extension is C and Java, and the same source is built for each system. From the Ring folder, with JAVA_HOME set to a JDK:
sh extensions/ringjava/buildgcc.sh # Linux: lib/libring_java.so and lib/ringjava.jar
sh extensions/ringjava/buildclang.sh # macOS: lib/libring_java.dylib and lib/ringjava.jarsetup.ring copies ringjava.jar and paramnames.txt to ring/lib on these systems (the extension looks for them next to the library). The JVM is loaded at run time from the JDK (libjvm.so, libjvm.dylib), so nothing links to a Java version.
The Linux build was tried on Ubuntu (WSL, Ring 1.28, JDK 21): the tests, the tutorials, the applications and a program made by ring2exe run there. macOS has not been tried yet.
A Java runtime of its own#
ring tools/javatools/makeruntime.ring builds a small Java runtime with jlink in ring/bin/jre (ring/lib/jre on Linux and macOS, next to the library):
ring tools/javatools/makeruntime.ring all the standard modules (about 60 MB)
ring tools/javatools/makeruntime.ring ../../bin/jre java.base,java.desktop,java.loggingring_java uses the folder jre next to the library before JAVA_HOME, so a program with this folder runs on a computer that has no Java. RINGJAVA_HOME and jUseJDK still win over it.
A program for other people#
ring2exe myprogram.ring -dist -java
ring tools/javatools/bundle.ring target/windows java.lang java.util javax.swing-javacopiesring_java.dll,ringjava.jar,paramnames.txtand the folderjre(when it exists) intotarget/windows. On Linux and macOS it copies the library and the jar, and the program needs Java 17 or later (the package dependencydefault-jreis added for Ubuntu).bundle.ringputs the Ring classes of the packages that the program uses intarget/windows/javalib/generated. Name every package ofusing { }, and the ones whose objects the program receives from Java and uses by their classes. Without names all the packages are copied (about 14 MB). The library inside the program looks for them there when its own folder does not exist.- Copy the
target/windowsfolder: it has everything. This was tested: the folder was copied elsewhere and the program ran with the Ring folder moved away,JAVA_HOMEempty and no Java on thePATH.
On Linux the steps are the same, with these differences (this was tried: the folder was copied to another place and the program ran with env -i, without JAVA_HOME, without Java on the PATH and without the Ring folder):
ring2exe myprogram.ring -dist -java
cp -r ring/lib/jre target/linux/dist_using_scripts/lib/jre # ring2exe copies the runtime only on Windows
ring tools/javatools/bundle.ring target/linux/dist_using_scripts/bin java.lang java.util
cd target/linux/dist_using_scripts && LD_LIBRARY_PATH=$PWD/lib ./bin/myprogramThe library is in lib (libring.so, libring_java.so, ringjava.jar, paramnames.txt and jre), the program in bin, and the generated classes in bin/javalib/generated, next to the program. The install scripts that ring2exe writes copy the libraries to /usr/lib; a runtime in lib/jre is then not next to libring_java.so: use LD_LIBRARY_PATH as above, or let the computer have Java 17 or later (the scripts install default-jre).
A program that uses Maven packages (jMaven) downloads them to ~/.ringjava/maven the first time it runs; to carry the jars with the program use jClasspath with the jar files and jImportFrom with classes that jGenerateClasses made.
Building the package (for the maintainer)#
git add -A
ring tools/javatools/makepackage.ring extensions/ringjava.zip: the files that git tracks under libraries, extensions/ringjava, samples, tools and binRun it again after any change of those folders, and commit the zip: RingPM installs from the repository.