Suppose I want to use just one method from that class:
CollectionUtils.isEmpty(list);
This is just a simplified example. In my actual use case, I’m working with a different custom JAR that provides specific functionality, unrelated to list utilities.
Is there a supported or recommended approach in Fantom (possibly using JFFI mechanism) to call such external Java methods?
You just have to make sure the Java code is your classpath or bundled into a dependent pod. You can run this from the command line to see what Fantom sees in your classpath:
fan compilerJava::ClassPath
Naren SWed 25 Jun
Hi Team,
Thanks a lot for your assistance on this topic — it worked for me!
I'd like to share a few key points from my experience that might help others looking to achieve the same:
Steps to Use External JARs in Fantom
1.Place the JAR in the appropriate directory Build your JAR and copy it to the following directory under your Fantom installation:
Naren S Tue 24 Jun
Hi Team,
I just wanted to check if there's a way to use methods from an external JAR file in a Fantom project using JFFI.
For example, let's say I have the following JAR file locally: commons-collections4-4.4.jar
Inside this JAR, there’s a Java class:
import org.apache.commons.collections4.CollectionUtils;
Suppose I want to use just one method from that class:
CollectionUtils.isEmpty(list);
This is just a simplified example. In my actual use case, I’m working with a different custom JAR that provides specific functionality, unrelated to list utilities.
Is there a supported or recommended approach in Fantom (possibly using JFFI mechanism) to call such external Java methods?
Appreciate your insights.
brian Tue 24 Jun
I'm sure you have seen the FFI chapter
You just have to make sure the Java code is your classpath or bundled into a dependent pod. You can run this from the command line to see what Fantom sees in your classpath:
Naren S Wed 25 Jun
Hi Team,
Thanks a lot for your assistance on this topic — it worked for me!
I'd like to share a few key points from my experience that might help others looking to achieve the same:
Steps to Use External JARs in Fantom
1.Place the JAR in the appropriate directory Build your JAR and copy it to the following directory under your Fantom installation:
/opt/homebrew/Cellar/fantom/1.0.80/libexec/lib/java/ext
2.Verify the JAR is loaded correctly You can confirm that your JAR has been recognized by running:
fan compilerJava::ClassPath
file:/opt/homebrew/Cellar/fantom/1.0.80/libexec/lib/java/ext/proto-buf-lib-1.0.0-all.jar
3.Call your Java class in Fantom
Import and use the Java class from your JAR as shown below:
using [java] org.apache.commons.collections4::CollectionUtils
List list := ArrayList() list.add("a") echo("List is empty: " + CollectionUtils.isEmpty(list))