#2944 Issue Loading External Java Class via JFFI in Fantom/Axon Environment

Naren S Thu 26 Jun

Dear Team,

I am currently integrating a Java library with a Fantom-based application and have encountered a JFFI-related issue. Specifically, I am attempting to reference a simple Java class from Fantom. While no method is being actively invoked, the application fails during class loading with a JFFI error when the Java class is used within an Axon function.

Here is a brief summary of the setup:

The Java class is a plain POJO with no external dependencies.

I have placed the compiled JAR under <fantom_home>/lib/java/ext and confirmed it appears using fan compilerJava::ClassPath.

The Java class is referenced from a Fantom class, which is then called via Axon.

The error occurs even before any Java method is invoked—only referencing the class causes the issue.

I have reviewed the documentation and ensured the JAR is structured correctly.

Reference: https://fantom.org/doc/docLang/JavaFFI

However, the problem persists, and I would appreciate your guidance on resolving this issue.

//Skyspark Axon Function, that is the start point of the program

() => do

echo("function called....")
readBuf() //fantom Axon method

end

//Fantom Axon Function call JavaTest.fan print function @Axon @NoDoc

static Obj readBuf(){
  echo("Parsing payload:")
  JavaTest test := JavaTest()
  test.print()
  return ""
}

//Fantom Class make Java declaration using [java] com.wesco.service::JavaTestService class JavaTest {

Void print() {
    echo("print..... ")
    JavaTestService service := JavaTestService()   // that defined lined create the error
}

}

Axon Function Error: errLast:

axon::EvalErr: Func failed: readBuf(); args: ()
  sys::Err: Method not mapped to java.lang.reflect correctly testConn::testFuncs.readBuf [proj_validate::readConstBuffer:15]
=== Axon Trace ===
  readConstBuffer (proj_validate::readConstBuffer:15)
  anon-1 (taskExpr:6)
=== Fantom Trace ===
axon::EvalErr: Func failed: readBuf(); args: ()
  sys::Err: Method not mapped to java.lang.reflect correctly testConn::testFuncs.readBuf [proj_validate::readConstBuffer:15]
  axon::FantomFn.callx (FantomFn.fan:117)
  axon::Fn.callLazy (Fn.fan:84)
  axon::Call.eval (Call.fan:39)
  axon::Block.eval (Block.fan:33)
  fan.sys.List.each (List.java:604)
  axon::Block.eval (Block.fan:33)
  axon::Fn.doCall (Fn.fan:115)
  axon::AxonContext.callInNewFrame (AxonContext.fan:182)
  axon::AxonContext.callInNewFrame (AxonContext.fan)
  axon::Fn.callx (Fn.fan:108)
  axon::TopFn.callx (Fn.fan:214)
  axon::Fn.callLazy (Fn.fan:84)
  axon::Call.eval (Call.fan:39)
  axon::BinaryMath.doEval (Operators.fan:501)
  axon::BinaryOp.eval (Operators.fan:65)
  axon::Fn.callLazy (Fn.fan:84)
  fan.sys.List.map (List.java:864)
  axon::Fn.callLazy (Fn.fan:84)
  axon::Call.eval (Call.fan:39)
  axon::Block.eval (Block.fan:33)
  fan.sys.List.each (List.java:604)
  axon::Block.eval (Block.fan:33)
  axon::Fn.doCall (Fn.fan:115)
  axon::AxonContext.callInNewFrame (AxonContext.fan:182)
  axon::AxonContext.callInNewFrame (AxonContext.fan)
  8 More...
Cause:
  sys::Err: Method not mapped to java.lang.reflect correctly testConn::testFuncs.readBuf
    fan.sys.Method$MethodFunc.isStatic (Method.java:496)
    fan.sys.Method$MethodFunc.callList (Method.java:205)
    fan.sys.Method.callList (Method.java:138)
    axon::FantomFn.doCall (FantomFn.fan:125)
    axon::AxonContext.callInNewFrame (AxonContext.fan:182)
    axon::AxonContext.callInNewFrame (AxonContext.fan)
    axon::FantomFn.callx (FantomFn.fan:113)
    axon::Fn.callLazy (Fn.fan:84)
    axon::Call.eval (Call.fan:39)
    axon::Block.eval (Block.fan:33)
    fan.sys.List.each (List.java:604)
    axon::Block.eval (Block.fan:33)
    axon::Fn.doCall (Fn.fan:115)
    axon::AxonContext.callInNewFrame (AxonContext.fan:182)
    axon::AxonContext.callInNewFrame (AxonContext.fan)
    axon::Fn.callx (Fn.fan:108)
    axon::TopFn.callx (Fn.fan:214)
    axon::Fn.callLazy (Fn.fan:84)
    axon::Call.eval (Call.fan:39)
    axon::BinaryMath.doEval (Operators.fan:501)
    axon::BinaryOp.eval (Operators.fan:65)
    axon::Fn.callLazy (Fn.fan:84)
    fan.sys.List.map (List.java:864)
    axon::Fn.callLazy (Fn.fan:84)
    axon::Call.eval (Call.fan:39)
    14 More...

Please let me know if you need any logs or a minimal reproducible project.

Naren S Fri 27 Jun

Solution for the Error:

When creating a connector and deploying it to SkySpark, you need to ensure that your JAR file is placed in both of the following locations:

<fantom_home>/lib/java/ext

skyspark-3.x.x/lib/java/ext

This ensures that SkySpark can recognize and load the Java classes from your JAR properly.

Login or Signup to reply.