Following is something I wrote for some colleagues last year - just thought I'd share it.
For those Newbies who can't see the wood for the trees.
A Quick Start To Fantom Development
This doc hopes to explain (concisely) how you might set up and use a typical Fantom dev environment. For the info presented here is scattered throughout the Fantom docs and is not too apparent from first glance.
To avoid complication, there are no IDEs in this section, we'll just assume plain text editors.
Install Fantom
Installing Fantom is no different to installing ant or maven.
To run this you first compile it into a .pod file (think .jar file). This is the job of build.fan:
class Build : build::BuildPod {
new make() {
podName = "example"
summary = "Wotever Example"
srcDirs = [`fan/`]
depends = ["sys 1.0"]
version = Version([1,0,0])
}
}
The above build.fan compiles our example.pod, and like .jar files, pods are just .zip files. (Note it's the BuildPod superclass that does all the hard work, all we do is configure it.)
srcDirs are URIs, hence the back quotes. All dirs are relative to build.fan and must end with a forward slash. Also dirs are not recursive, so if we had public and internal source dirs, srcDirs would look like:
Pods automatically get saved into /apps/fantom/lib/fan/ along with all the other Fantom system pods. So example.pod is now part of the Fantom install.
Run Your Application
The .pod is run in the same way as any (system) Fantom application:
> fan example::Wotever
Fantom. Wotever.
Note the pod::class notation.
Note also we didn't have to specify a class path or similar. Everything is taken from the Fantom install, even our example.pod. This simplifies execution quite a bit.
Let's make it even easier to launch our application, lets make a Main.fan like so:
Now we can run our app by just specifying the pod:
> fan example
My main() man.
Fantom. Wotever.
Note how if no class is specified, Fantom looks for one called Main. Also, if no method is specified, Fantom looks for one called main. If the method is an instance method, Fantom creates an instance via a no-args constructor.
e.g. to call the main method directly we could type:
SlimerDude Sat 9 Mar 2013
Following is something I wrote for some colleagues last year - just thought I'd share it.
For those Newbies who can't see the wood for the trees.
A Quick Start To Fantom Development
This doc hopes to explain (concisely) how you might set up and use a typical Fantom dev environment. For the info presented here is scattered throughout the Fantom docs and is not too apparent from first glance.
To avoid complication, there are no IDEs in this section, we'll just assume plain text editors.
Install Fantom
Installing Fantom is no different to installing
ant
ormaven
./apps/fantom/
FAN_HOME = /apps/fantom
Path
environment variable to include%FAN_HOME%/bin
(windows notation) or$FAN_HOME/bin
(*nix notation)Run a Fantom Script
Every Fantom source file can be run like a script with the
static Void main(Str[] args)
method being invoked.Lets make a file called
Wotever.fan
which looks like:We can now run it with the following fan command:
That maybe fine for a simple single file, but what of a Fantom project with multiple source files? Well...
Create and Build a Fantom Application
The typical dir structure for a simple application project looks like:
All the source files go in the
fan
dir (with the exception of the specialbuild.fan
). Lets make a Hello World; editWotever.fan
to be:To run this you first compile it into a .pod file (think .jar file). This is the job of
build.fan
:The above
build.fan
compiles ourexample.pod
, and like .jar files, pods are just .zip files. (Note it's theBuildPod
superclass that does all the hard work, all we do is configure it.)srcDirs
are URIs, hence the back quotes. All dirs are relative tobuild.fan
and must end with a forward slash. Also dirs are not recursive, so if we hadpublic
andinternal
source dirs,srcDirs
would look like:The syntax for dependant pods requires both the pod name and the version, see Depend for full details.
Lets run
build.fan
as a script:Pods automatically get saved into
/apps/fantom/lib/fan/
along with all the other Fantom system pods. Soexample.pod
is now part of the Fantom install.Run Your Application
The .pod is run in the same way as any (system) Fantom application:
Note the
pod::class
notation.Note also we didn't have to specify a class path or similar. Everything is taken from the Fantom install, even our
example.pod
. This simplifies execution quite a bit.Let's make it even easier to launch our application, lets make a
Main.fan
like so:Now we can run our app by just specifying the pod:
Note how if no class is specified, Fantom looks for one called Main. Also, if no method is specified, Fantom looks for one called main. If the method is an instance method, Fantom creates an instance via a no-args constructor.
e.g. to call the main method directly we could type:
Have fun.