#1669 can I compile fantom scripts?

Xan Sat 8 Oct 2011

Hi,

In java, there is javac, and in scala, there is scalac. Is there an equivalent in fantom? Is it planned? I ask for more fast scripts...

Thanks, Xan.

DanielFath Sat 8 Oct 2011

What are you asking for?

fan.exe or fan <command> is how you compile scripts in fantom. See this for more info.

To make a "script" in fantom you can just say:

//file hello.fan
class Main
{
   static Void main() { echo("hello world #3") }
}

//type in command prompt
fan hello.fan

You can't say:

//file oneliner.fan
echo("hello world #5")
//this won't work
//fan oneliner.fan

You need a class and a static Method that is called main to start. If you want to use something from other pods you need to create a full fledge pod and declare your dependency. Otherwise you are limited to only sys pod iirc.

brian Sat 8 Oct 2011

To run a script you just use "fan" command line launcher with a file argument.

To precompile a Fantom pod is not exactly like Java, because precompilation isn't used to create classfiles, rather you create first class modules (pods). Because lots of information is needed to build a full pod (depends, description, metadata, resources, etc), we don't have a simple "fanc" command line program. Rather we have a standard build script that can be used to define the module metadata and build different targets of the pod.

See docTools::Build - this is basically what "javac" is in Fantom.

Xan Tue 11 Oct 2011

Thanks Brian. Is there any way for making classfiles?

Thanks, Xan.

brian Tue 11 Oct 2011

In general its is best to use the Fantom runtime to emit classfiles at load time. This provides maximum flexibility to handle the fragile base class problem for mixins.

But you can also look at JarDist and example

Xan Wed 12 Oct 2011

This is what I want. Thanks a lot Brian.

Login or Signup to reply.