#2556 F4 and Java Issue

jhughes Mon 15 Aug 2016

Looking to get started with Fantom and need to be able to pull in some existing java classes. I ran through the example here,http://www.alienfactory.co.uk/articles/intro-to-f4. for setting up the F4 IDE to test some of the pure Fantom examples and that worked no problem. Tried to bring in the Java examples and run into a couple of problems.

  1. When I try to run any of the examples I get an "Invalid Uri scheme for local file" error. Based on past experience with this kind of thing, i'm going to assume this is because there is a space in my windows user name and the compiler doesn't know how to handle that.
  2. The hello.fan file shows one error: Description Resource Path Location Type Ambiguous type: sys::Void, [java]java.lang::Void hello.fan /Examples/fan/java /Examples/fan/java/hello.fan Fantom Problem

There seems to be no documentation anywhere that I can find on resolving this type of issue though so i'm kind of stuck on getting started if I want to bring in any existing java code into a fantom project.

SlimerDude Mon 15 Aug 2016

Hi jhughes,

  1. I think this just requires more understanding of file URIs on Windows...

    I doubt Invalid Uri scheme for local file has anything to do with spaces, instead look for a file URI that has an absolute path including a drive:

    `C:/my/absolute/path.txt`

    Note that C is interpreted as a scheme like http but is not valid for file systems. Instead ensure the URI starts with a / so Fantom knows that C: is part of the path:

    `/C:/my/absolute/path.txt`

    Or to be extra safe and sure, make sure it has the file scheme:

    `file:/C:/my/absolute/path.txt`

  2. The hello.fan example needs updating. The compiler is getting confused between Java's Void and Fantom's Void. Adding an extra using statement to distinguish between the two should help:
    using [java] java.lang
    using [java] java.lang::Void as JVoid
    
    **
    ** Hello world using System.out.println
    **
    class HelloWorld
    {
      Void main()
      {
        System.out.println("Java FFI hello world")
      }
    }

Hope this helps,

Steve.

jhughes Mon 15 Aug 2016

  1. Where would I go about changing the URI in this case? All I've done at this point is start a project in F4 and bring in the example files. Not really sure where to go in the IDE to modify how it's resolving the file URI or if that's even an IDE issue.
  2. The extra using line has resolved that error, thanks.

SlimerDude Mon 15 Aug 2016

Where would I go about changing the URI in this case?

I don't know. Without a stacktrace, or knowing which example you're running, or even a complete error message, I can't really say what might be going wrong.

jhughes Mon 15 Aug 2016

This is concerning the hello.fan example for using java.

[14:56:15 15-Aug-16] [err] [pathenv] Cannot parse path: C:\Users\Jonathan Hughes\f4workspace\FantomExamples\bin\fan;C:\Fantom\Examples\bin\fan

sys::ArgErr: Invalid Uri scheme for local file: c:\Fantom\Examples\bin\fan/
  fan.sys.LocalFile.uriToFile (LocalFile.java:64)
  fan.sys.File.make (File.java:26)
  util::PathEnv.parsePath (PathEnv.fan:61)
  fan.sys.List.each (List.java:588)
  util::PathEnv.parsePath (PathEnv.fan:57)
  util::PathEnv.make$ (PathEnv.fan:25)
  util::PathEnv.make (PathEnv.fan:22)
  java.lang.reflect.Method.invoke (Unknown)
  fan.sys.Method.invoke (Method.java:559)
  fan.sys.Method$MethodFunc.callList (Method.java:198)
  fan.sys.Type.make (Type.java:246)
  fan.sys.ClassType.make (ClassType.java:110)
  fan.sys.Type.make (Type.java:236)
  fan.sys.Sys.initEnv (Sys.java:462)
  fan.sys.Sys.<clinit> (Sys.java:235)
  fanx.tools.Fan.execute (Fan.java:28)
  fanx.tools.Fan.run (Fan.java:308)
  fanx.tools.Fan.main (Fan.java:346)

ERROR: sys::UnknownPodErr: examples

I've attempted to get this resolved referencing the topic about getting the examples running (http://fantom.org/forum/topic/2334). Imported the example F4 project and put the hello.fan java example into it and get the same stack trace but with a slightly different error. The exact same stack trace actually exists in all the example files for that project for me but still manage to run the code after it.

[14:59:32 15-Aug-16] [err] [pathenv] Cannot parse path: C:\Users\Jonathan Hughes\f4workspace\FantomExamples\bin\fan;C:\Fantom\Examples\bin\fan

sys::ArgErr: Invalid Uri scheme for local file: c:\Fantom\Examples\bin\fan/
  fan.sys.LocalFile.uriToFile (LocalFile.java:64)
  fan.sys.File.make (File.java:26)
  util::PathEnv.parsePath (PathEnv.fan:61)
  fan.sys.List.each (List.java:588)
  util::PathEnv.parsePath (PathEnv.fan:57)
  util::PathEnv.make$ (PathEnv.fan:25)
  util::PathEnv.make (PathEnv.fan:22)
  java.lang.reflect.Method.invoke (Unknown)
  fan.sys.Method.invoke (Method.java:559)
  fan.sys.Method$MethodFunc.callList (Method.java:198)
  fan.sys.Type.make (Type.java:246)
  fan.sys.ClassType.make (ClassType.java:110)
  fan.sys.Type.make (Type.java:236)
  fan.sys.Sys.initEnv (Sys.java:462)
  fan.sys.Sys.<clinit> (Sys.java:235)
  fanx.tools.Fan.execute (Fan.java:28)
  fanx.tools.Fan.run (Fan.java:308)
  fanx.tools.Fan.main (Fan.java:346)

ERROR: sys::UnknownTypeErr: FantomExamples::HelloWorld

SlimerDude Mon 15 Aug 2016

Thanks, if the error is from PathEnv and happens for all Fantom programs then it strongly suggests that you have a bad FAN_PATH_ENV environment variable set up.

Assuming you've not set anything up in F4, can you report what the following says when typed into a standard command prompt:

C:\> set fan

For comparison, mine says:

C:\>set fan
FAN_ENV=
FAN_ENV_PATH=C:\Repositories-Fantom\workDir
FAN_HOME=C:\Apps\fantom-1.0.69

Note that having a FAN_ENV_PATH environment variable is completely optional, and should only exist if you wish to make use of PathEnv or a customised FPM Env.

If you do have an FAN_ENV_PATH (and / or a FAN_ENV) environment variable then I would suggest removing them until the basic examples are working.

jhughes Mon 15 Aug 2016

C:\Users\Jonathan Hughes>set fan Environment variable fan not defined

Noting appears to be setup concerning those variables so I don't have anything to remove.

SlimerDude Tue 16 Aug 2016

Okay, I see partly what's going on.

You're using F4 v1.0.2 - this older version sets up PATH_ENV_PATH for you when launching programs.

Note that this error should not prevent your programs from running. If Fantom can't initialise PathEnv then I believe it defaults to using BootEnv and carries on. The only time you would need PathEnv is when you have multiple related projects open in F4 - which I assume you don't right now.

I tried to deduce (by matching up your stack trace with different Fantom versions), that you've added an interpreter to F4 for Fantom 1.0.69 - is that correct?

If so, I cannot reproduce your error. I downloaded a clean install of F4 1.0.2 & Fantom 1.0.69 and created a new project, in a path with spaces (just to make sure!) and ran the following, error free:

F4-hello.png

Does your project look much different?


In any case, I would strongly recommend downloading a preview of F4 v1.1.0 from the nightly builds, for as mentioned in other threads, it solves a lot of problems.

Note the new version uses a bespoke F4Env as its Fantom environment and not PathEnv so it may fix your URI parsing issue. If the problem does re-manifest itself, then I can always patch F4Env.

jhughes Tue 16 Aug 2016

I'll start by letting you know that after installing the nightly build and opening in the same work space, so essentially nothing else changed, code runs without errors.

Thanks for pointing me to that page.

Now to answer the questions about this issue:

There is only one download link on the F4 website you are directed to from the IDE link in the docs section of fantom (http://www.xored.com/products/f4/) and that's what downloaded when I set this all up yesterday. Side note, the about in that version still shows 1.0.1 but apparently it's a really old version so i'm not going to worry about that.

Not sure how you or where the nightly builds site was discovered if the main F4 website doesn't even host the latest or seemingly a link to that site anywhere on the page but that's a big hindrance of this IDE has this many gotchyas just to set up hello world.

You are correct in the pairing, F4 and Fantom 1.0.69. The picture you posted is not visible so I can't tell you if they look different.

Did you test with the same missing environment variables that I had or were they setup on your machine? Just curious why it would work on your system with a clean install when that's exactly what I did yesterday when I started this.

Hope somebody starts to maintain that download site on the main F4 page or the fantom docs can get updated to point to the nightly builds since whatever's on that site right now is problematic at best.

jhughes Tue 16 Aug 2016

Now that I got hello.fan to run with java in the IDE, I copied the jar I really wanted to start using within fantom to fantom/lib/java folder and it shows up in the Fantom Native Libraries in the IDE. I created a new fantom class to inherit one of the classes from the jar but when I attempt to import I get: "No FFI Bridge for 'jarName'.

Are there more steps that need to be taken in the IDE to allow jars to be recognized?

jhughes Tue 16 Aug 2016

Disregard the last comment. I figured out what I did wrong.

Login or Signup to reply.