#2334 How to run the examples?

rasa Sun 24 Aug 2014

As I'm a newbie to Fantom and Eclipse (F4), is there anyone who could give me a step-by-step tutorial on how to make F4 project from the examples found in the Fantom distribution and to run them also?

Hertz Sun 24 Aug 2014

This is what worked for me.

  1. Create a new fantom project in f4 file > new fantom project
  2. You can name it examples or another name of your choosing
  3. Once the project is created delete the empty fan folder
  4. From you system's file manager/explorer open LOCATION_TO_FANTOM/examples folder
  5. Copy the 8 example folders. Select them all Ctr-V for windows or right click > copy
  6. Go into f4, right click on examples project( or whatever you called it), and click paste.
  7. Open up a .fan file from the folders and run it like normal.

If you have any other questions you can ask.

rasa Sun 24 Aug 2014

No, it didn't work. You must be wrong somewhere.

Hertz Sun 24 Aug 2014

Hmm? Where is the problem occurring? Also what computer platform are you running on?

rasa Mon 25 Aug 2014

I'm using Win7 64bit. I'd tried to run sys:stmts.fan and here is what I got:

[10:25:32 25-Aug-14] [err] [pathenv] Cannot parse path: C:\Users\rasa\f4workspace\Fantom v1.0.66 Examples\bin\fan
  sys::ArgErr: Invalid Uri scheme for local file: c:\Users\rasa\f4workspace\Fantom v1.0.66 Examples\bin\fan/
  fan.sys.LocalFile.uriToFile (LocalFile.java:64)
  fan.sys.File.make (File.java:24)
  util::PathEnv.parsePath (PathEnv.fan:47)
  fan.sys.List.each (List.java:534)
  util::PathEnv.parsePath (PathEnv.fan:43)
  util::PathEnv.make$ (PathEnv.fan:22)
  util::PathEnv.make (PathEnv.fan:20)
  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:245)
  fan.sys.ClassType.make (ClassType.java:110)
  fan.sys.Type.make (Type.java:235)
  fan.sys.Sys.initEnv (Sys.java:447)
  fan.sys.Sys.<clinit> (Sys.java:224)
  fanx.tools.Fan.execute (Fan.java:28)
  fanx.tools.Fan.run (Fan.java:298)
  fanx.tools.Fan.main (Fan.java:336)
ERROR: sys::UnknownPodErr: C:/Users/rasa/f4workspace/Fantom

SlimerDude Mon 25 Aug 2014

Are you running it from the cmd line? Does the directory C:\Users\rasa\f4workspace\Fantom v1.0.66 Examples\bin\fan exist?

Are you purposely setting / using a PathEnv? If not, try un-setting the environment variable and re-running the example.

C:\> set FAN_ENV=
C:\> fan stmts.fan

rasa Mon 25 Aug 2014

@Hertz told me to delete fan folder that were made by F4 New project wizard. Now I made new fan folder and moved all examples into it. Next, I'd tried to navigate to that folder manually and ran this example:

C:\Users\rasa\f4workspace\Fantom v1_0_66 Examples\fan\sys>fan lists.fan

It worked. It works for other examples too.

But note that I'm inexperienced Eclipse user, so maybe I'm doing something wrong in F4. 1) open project (all examples are in fan folder) 2) open lists.fan in editor 3) click on "Run As..." 4) a dialog "Run As" pops up giving me the options: "Fantom class" and "Fantom testing" 5) I choose "Fantom class" 6) erros show up!

I still don't know how to run lists.fan as a script inside F4.

rasa Tue 26 Aug 2014

Is there anybody who uses F4 under Win7? I've managed to run examples only using NetBeans IDE but failed with F4 and Camembert. I couldn't even start Camembert. Also tried Fantom plugin for IntelliJ IDEA, but it doesn't work for IDEA v13. Authors have stopped working on it since IDEA v9. Source code is unavailable.

Is there someone who is in the mood to run Fantom examples in Win7 using F4 IDE and test if they could be ran without problems?

brian Tue 26 Aug 2014

@rasa,

Based on the one exception you posted, make sure you are using proper URIs and not Window's file paths if you have any configuration files. Everything in Fantom uses URIs for the most part. To check a Window's path as URI in fansh:

File.os("windows path")

rasa Tue 26 Aug 2014

fansh just prints: windows path

p.s. I can start examples in NetBeans because there is an option "Run as a script" if I remember well. There is no such option in F4 so I can't solve the problem.

SlimerDude Tue 26 Aug 2014

Is there anybody who uses F4 under Win7?

Yep - me! F4 under Win7 64 bit to be exact.

in NetBeans there is "Run as a script" There is no such option in F4.

Right click, "Run As... Fantom Class" runs the class as a Fantom script. You are doing the right thing.

From your exception:

[err] [pathenv] Cannot parse path: C:\Users\rasa\f4workspace\Fantom v1.0.66 Examples\bin\fan

I imagine that the path does not exist. To check, in fansh type:

File.os("C:\Users\rasa\f4workspace\Fantom v1.0.66 Examples\bin\fan")

(Note that windows path has been substituted with the, um, Windows path!)

Anyway, I strongly suspect that you have a project mis-configured in F4.

F4 does not really deal with individual Fantom files, but rather Fantom projects so we need to ensure the project is setup correctly before we can run the classes / scripts.

In the project directory you will find 3 F4 text files, .project, .classpath and .buildpath (F4 hides these because they start with a dot, so use a normal Windows explorer / notepad to open them). If you post the contents of those 3 files AND build.fan I'll have a look and see what I can spot.

Oh, and close ALL projects except the one with the examples.

rasa Tue 26 Aug 2014

Oh, I taught that "windows path" was some key. Sorry.

fansh> File.os("C:/Users/rasa/f4workspace/FantomExamples/bin/fan")
/C:/Users/rasa/f4workspace/FantomExamples/bin/fan

Note that I had to change backslash into forwardslash in order to execute File.os Otherwise fansh argued with: ERROR(17): Invalid escape sequence

Note that I've made a new project, so now the root folder is named FantomExamples. Inside that project I have only one folder named "fan" and 3 config files. 4th file build.fan seems to be aded uppon compiling, but I'm not sure about that. I have no idea why F4 reports that it cannot parse the path "C:\Users\rasa\f4workspace\FantomExamples\bin\fan" when the folder "bin" doesn't even exists?

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>FantomExamples</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.dltk.core.scriptbuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>com.xored.fanide.core.nature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
</projectDescription>

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="com.xored.fanide.jdt.launching.FANJAVA_CONTAINER"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="output" path="bin"/>
</classpath>

.buildpath

<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
	<buildpathentry kind="src" path="fan"/>
	<buildpathentry kind="con" path="org.eclipse.dltk.launching.INTERPRETER_CONTAINER"/>
</buildpath>

build.fan

using build
class Build : build::BuildPod
{
  new make()
  {
    podName = "FantomExamples"
    summary = ""
    srcDirs = [`fan/`, `fan/web/`, `fan/web/demo/`, `fan/util/`, `fan/sys/`, `fan/js/`, `fan/java/`, `fan/fwt/`, `fan/email/`, `fan/concurrent/`]
    depends = ["sys 1.0"]
  }
}

SlimerDude Tue 26 Aug 2014

I think I see.

When I mentioned F4 builds Fantom projects, more specifically I mean it builds Fantom pods. One F4 project builds one Fantom pod.

All the example files in the different directories can not (without modification) be built into a single pod. Mainly because to build a Fantom pod, all the class names in all the .fan files have to be different and all the .fan files need to have different names.

I imagine you have a couple of red crosses in your project, which looks like:

F4 Project with Errors

In F4, when you run a class as a script, it runs it from the built .pod. If you have errors / red crosses in your project (or problems in the Problems View) then the .pod is not being built and you will not be able to run classes without error.

So we're going change the FantomExamples project to just contain the files from fan/sys/ directory. Delete the other directories and copy the contents of fan/sys/ into fan/ and delete fan/sys/. Refresh the project in F4 (Right-click on the project -> Refresh (F5)) and it should look like this:

F4 Project without Errors

Note that reflection.fan needs fwt added as dependency to build.fan. Afterwards, your build.fan should look like:

using build
class Build : build::BuildPod
{
  new make()
  {
    podName = "FantomExamples"
    summary = ""
    srcDirs = [`fan/`]
    depends = ["sys 1.0", "fwt 1.0"]
  }
}

You project should now have no red crosses! And the Problems View should be clear. ( Window -> Show View -> Problems if you can't see the Problems View).

Now you should be able to right click on any .fan file, in either the Fantom Explorer View or the Editor, and Run As... -> Fantom Class.

If you're still having trouble, I've zipped up a working F4 project for the sys examples here: fantomExamples.zip

More Info on .pods

As mentioned earlier, F4 runs the class from the .pod file. By default the .pod file is build to:

<project-dir>/bin/fan/lib/fan/<project-name>.pod

So you can look for it there. If you clean the project (Project -> clean...) then the .pod file should get rebuilt. So if you delete the .pod file and clean the project, you should see it getting rebuilt.

If the pod does not get re-built, you still have an error in your F4 project.


I've never tried to run the Fantom examples from within F4 before, and um, yes, it does not appear to be not straight forward.

@Brain n @Andy: What do you think about modifying the examples/ dir so that it builds an examples.pod?

Still have each file executable as a script, but maybe tidy up the class and file names so that they're all different and alter the build.fan so it has the correct dependencies and compiles all the examples into one pod?

SlimerDude Tue 26 Aug 2014

I had to change backslash into forwardslash in order to execute

Oh yeah... backslashes in URIs need to be escaped with a backslash:

fansh> File.os("C:\\Users\\rasa\\f4workspace\\FantomExamples\\bin\\fan")

(But if the project / pod wasn't being built then that would have been a red-herring anyway.)

rasa Wed 27 Aug 2014

OK, I understand, but I don't want to make many small projects as it is alredy possible to run all scripts inside NetBeans without slicing them into independable pods. So, i tried refactoring. I had to rename only 3 files:

  1. java/hello.fan -> java/hellojava.fan
  2. web/demo.fan -> web/demoweb.fan
  3. js/demo.fan -> js/jsdemo.fan Next, I filled missing dependencies in buid.fan: depends = ["sys 1.0", "build 1.0", "compiler 1.0", "compilerJs 1.0", "concurrent 1.0", "email 1.0", "fwt 1.0", "gfx 1.0", "util 1.0", "web 1.0", "webmod 1.0", "wisp 1.0"]

Than, deleted netbeans folder as it is not necessary.

The only problem left is in the hellojava.fan Problems view says:

Ambiguous type: sys::Void, [java]java.lang::Void	hellojava.fan	/FantomExamples/fan/java

Don't know what is all about. Commented whole main method in this class to make F4 and its Problems view happy. Then I started other examples and everything was OK.

Here I have some questions and advices:

  1. How can I resolve mentioned problem?
  2. Is there any way I can switch off annoying "Run As" window in F4?
  3. Make examples project for F4 as SlimerDude suggested for there is a config file for NetBeans already.
  4. How do i know what version numbers to put into pod dependencies? It seems that compiler will notify me what versions do I need for compiling. Am I right? And then, if I'm right, how and where do I search for the right version?

SlimerDude Wed 27 Aug 2014

So, i tried refactoring.

Well done! I didn't want to give you any more extra steps!

  1. In hellojava.fan replace the using line with
    using [java] java.lang::System

    This imports / uses only the Java System class which prevents a conflict between the 2 Void classes. (Fantom and Java's.) The conflict is probably an F4 bug.

  2. Don't know what you mean.
  3. ...
  4. See the Depends class for version syntax. sys 1.0 actually means sys 1.0.* so it happily matches sys 1.0.66; the current Fantom version.

    It seems that compiler will notify me what versions do I need for compiling.

No, it uses whatever you put in build.fan.

Note that you can only have ONE version of a pod in any given Fantom environment; which is hinted at by the fact .pod files don't have version numbers.

rasa Wed 27 Aug 2014

  1. that solved the problem
  2. every time I click "Run As" in F4, a Dialog "Run As" appears forcing me to choose, i.e. click on, one of two options: "Fantom Class" and "Fantom Testing". OK button is disabled till I choose something. There is no default selection also. Popping of this window every time i want to run some script is really annoying. What is the way to suppress its appearance?

    Note that you can only have ONE version of a pod in any given Fantom environment; which is hinted at by the fact .pod files don't have version numbers.

    • Why then one have to put version numbers in dependencies list?
    • What is the best strategy for installing pods? To put its latest versions or what? What if the functionality of some pod changes between versions? I really don't understand how only one pod can be enough for full functionality?

p.s. How do I attach an image to the post?

SlimerDude Wed 27 Aug 2014

Click the down chevron next to the Run As button:

Run As Button

And that brings up a list of recent Run Configurations. Whatever you ran last should be towards the top of the list.

Why then one have to put version numbers in dependencies list?

To make sure you're using the correct version for the project!

Fantom pods are stored and managed with fanr.

How do I attach an image to the post?

You can't. You have to upload your image to somewhere on the web and link to it using the image syntax.

rasa Wed 27 Aug 2014

And, that's it? I always have to click on down chevron and then choose run configuration. It is impossible to set default run config or use keyboard shortcut?

SlimerDude Wed 27 Aug 2014

I googled:

eclipse run history shortcut

and the top hit was Is there a shortcut in Eclipse to Re-run the most recently launched program?

rasa Wed 27 Aug 2014

OK. Where is that option in F4?

tomcl Sun 31 Aug 2014

Eclipse is maddening.

It is a very highly capable IDE, but when first learning it the things that you want to do with a simple project are more complex than you'd expect.

F4 still looks very good once it is properly configured - though because its developers seem to have stopped I do worry whether this will remain.

The things that are awkward for me: (1) standard compile and launch needing two clicks - the above key shortcut looks the best workaround, if it works (seems not to on my Mac). And anyway the twi clicks are not too bad.

(2) build & run (or build and debug) will run the last working version on compiler failure. Of course what you WANT is for the process to stop on compile failure.

This one is really annoying. The solution I've found is a bit messy but works. F4 "build" will run the build script. You can alter this by overriding the called method of Build so that compile failure will exit and not run the code.

(3) as the OP said, what is needed is a step by step bomb-proof tutorial for how to get started with F4 and Fantom so that those new to the language can get started on 64 bit win7 or (yuk) win8 without 3 hours checking configurations and experimenting. It is not simple because you have choice of 32/64 bit Java (and different versions) and 32/64 bit F4.

This tutorial needs to include stuff about how to set up your Fantom project and source file(s), how to alter build.fan to decent "compile and run only if compile succeeds" behaviour, etc. All if possible in a shrink-wrapped form.

SlimerDude Sun 31 Aug 2014

its developers seem to have stopped

Ivan still does some tweaks now and then. The source is available on GitHub and can be built with maven.

Editors in general are a very personal thing... here is my take on your points:

  1. Launching is not an issue for me. Either I'm running a BedSheet app which re-deploys itself when pods change or I'm re-running unit tests which is just a button click on the Script Unit Test view.
  2. Again, not really an issue for me. A quick glimpse at the Problems View tells me if I have errors, and I don't run anything if errors exist.

    Ivan did commit a fix for this, but in my opinion it (unfortunately) causes more issues than it fixes.

    I think your idea of altering build.fan is probably the best for now.

  3. I tried writing a tutorial here:

    An Introduction to the F4 IDE

There are (and were) other issues that annoy me more. I listed most of them as GitHub Issues.

rasa Mon 1 Sep 2014

Vote here for IntelliJ IDEA plugin update.

rasa Thu 4 Sep 2014

I've managed to run examples in F4 successfully, but that was at my work site comp. Now I tried to do the same at home and failed with an already well known error:

[err] [pathenv] Cannot parse path: C:\Users\rasa\f4workspace\Fantom v1.0.66 Examples\bin\fan

I taught that I had resolved that error by doing all the steps above but it seems that I solved it accidentally. By comparing project and F4 configurations at home and at the work place I have discovered that all configs are identical. But then I compared project folders in file manager (not visible in project tree) and discovered that I really have the bin folder in my work comp and that there is no such folder in home comp. Here is how this folder looks like:

bin\fan\lib\fan\FantomExamples.pod

I have copied this folder into the project folder of my home comp and ran the examples without errors. The problem is that I'm not aware how I have created this folder structure at work comp? It's created by F4 but I don't know how and when that happened?

SlimerDude Thu 4 Sep 2014

From my observations, the directory structure (and pod) are created by F4 when the project successfully compiles for the first time. If your project never compiled then the directory structure (and pod) would not be created.

rasa Fri 5 Sep 2014

Not sure about that. There were no problems or warnings during compilation but project pod was not created.

Login or Signup to reply.