Scripal is most efficient when using UTF-8 as base encoding in Java (standard since Java 18). Check default encoding by calling Charset defaultCharset(). Using other encodings causes some performance overhead.
Scripal relies on https://github.com/java-native-access/jna , Java Native Access.
This Library must be available.
The Java module is base.java. It consists of only one file.
See how to use Scripal in Java TestScripal.java
Make sure to specify the correct path to the Scripal shared library when calling scripal.base.baseInit(path).
This must be a path to the folder holding libscripal.so oder scripal.dll.
The function must be called once to initialize the library.
Every single thread must call scripal.base.libInit(config, encoding) to specify the entire path to the config file used (leave empty for default) and the encodig of the OS environment. scripal.base.ENC_DEFAULT will denote the standard.
You must specfiy the JNA jar in CLASSPATH when using Scripal.
To create classes under ./scripal folder, call javac.
Example for Linux
javac -d . -cp "/usr/share/maven-repo/net/java/dev/jna/jna/debian/jna-debian.jar" base.java
Example for Windows
javac -d . -cp ".\jna-jpms-5.16.0.jar" base.java
Alternative: You may use the included Jar files under https://github.com/scripal-git/scripal/blob/main/wrapper/java/linux or https://github.com/scripal-git/scripal/blob/main/wrapper/java/win.
Assuming that the scripal package and its classes are available in the classpath.
Linux: example call with (find out the path to jna-xxx.jar)
java -cp "./linux/scripalwrapper.jar:/usr/share/maven-repo/net/java/dev/jna/jna/debian/jna-debian.jar" TestScripal.java
Windows: example call with (find out the path to jna-xxx.jar)
java -cp ".;.\windows\scripalwrapper.jar;.\jna-jpms-5.16.0.jar" TestScripal.java
To avoid warnings with native access, set --enable-native-access=ALL-UNNAMED when calling Java.
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import scripal.*; public class MyScripal { public static void main(String[] args) throws IOException { String os = System.getProperty("os.name"); // init functions String lpath = ""; String osName = System.getProperty("os.name").toLowerCase(); if (osName.contains("linux")) { lpath = ""; } if (osName.contains("win")) { lpath = "..\\..\\win\\x64\\Debug"; } scripal.base.baseInit(lpath); scripal.base.libInit("", scripal.base.ENC_UTF8); scripal.base.logInit("stdout"); scripal.base.TFScripal obj = new scripal.base.TFScripal("source", "match find(bow 'a'); ifMatch matchEnd find(eow); loop;"); boolean result = obj.match("Find the words apple, ape and award."); System.out.println("source match result: " + result + " , no. of results: " + obj.getResultSize()); for (int i = 0; i < obj.results.size(); i++) { System.out.println(obj.results.text.get(i) + " [" + String.valueOf(obj.results.positions.get(i)[0]) + "," + String.valueOf(obj.results.positions.get(i)[1]) + "]"); } } }
for more information see matching with Scripal and library