#2818 f4 IDE and Java FFI error

small_petit Wed 16 Dec 2020

Hello, I am trying to run the simple Java FFI Hello World program from https://fantom.org/doc/examples/java-hello with f4 IDE.

I created a new project, and the Fantom class in the /fan directory.

My build.fan looks like:

...
...
depends = ["sys 1.0"]

f4 IDE keeps showing the error Unknown variable System

I can easily run the same program on the command line and it runs just fine but f4 keeps complaining.

Please what am I missing? Thank you.

SlimerDude Wed 16 Dec 2020

Hi small_petit, that error sounds more like an issue with the way F4 is set up, rather than anything to do with the build.fan.

Can you shed any more light on how your project is set up?

small_petit Wed 16 Dec 2020

Hi SlimerDude, from your alien factory website I installed f4:

1) Downloaded and unzipped it

2) I added the -vm option to the f4.ini file to point to my Java directory. I am using AdoptOpenJDK 11

3) I started f4.exe and set up the Fantom interpreter to point to 1.0.75

4) Then I create new projects via File>New Project....

5) I have been able to run a lot of Fantom projects. But I have some little issues when it comes to Fwt and now Java FFI.

Thank you.

SlimerDude Thu 17 Dec 2020

Oh, okay!

Just calling Java from Fantom shouldn't be a problem. I tried that small example and got a different compilation error in F4 (to do with an ambiguous Void class), but a compilation error non-the-less.

Try this example instead that explicitly identifies which System to use:

using [java] java.lang::System

** Hello world using System.out.println
class HelloWorld {
  Void main() {
    System.out.println("Java FFI hello world")
  }
}

small_petit Thu 17 Dec 2020

Thanks for the assistance SlimerDude. Unfortunately, this is still not working.

This is the error I get:

Type not found in pod '[java]java.lang::System'

Regards

SlimerDude Thu 17 Dec 2020

Ah, I've been able to replicate the error using an install of JDK 14.

I think for Java FFI in F4 you'll still need Java 8. I get this warning in F4 when looking at the Java installation:

Java Warning

Trying installing Java 8. I would just download the .zip version and add it to F4 via Window -> Preferences -> Java -> Installed JREs

Then update the JDK your F4 project uses by right clicking on the JRE library and selecting Properties.

Java JRE

Java 8 is the default I use for all my work.

small_petit Thu 17 Dec 2020

Yes. All done. I did as you instructed and everything works fine.

Thank you SlimerDude

Login or Signup to reply.