Automatic Class Loading
Automagic, sorry, automatic class loading is Jangaroo's ability to detect the set of classes needed to run a main class, i.e. the set of transitive imports or dependencies of that class.
Imagine a project with many, many classes (after all, we claim to support "programming in the large"). For loading the compiled script code into the HTML page, so far, you know about three options:
- Write down a <script src="..."> element for each single class.
- Write JavaScript code using the joo.classLoader.load() method to load each single class.
- Concatenate all needed classes in your build script (Ant or Maven) into one or more big *.js files and load these with <script src="..."> elements.
Wouldn't it be nice to only specify the main class to start from, and Jangaroo took care of loading all dependent classes? It is already possible!
The Jangaroo compiler passes all import directives to the Jangaroo runtime. The runtime keeps a list of all loaded classes and schedules any imported, but not yet loaded class for loading. The method joo.classLoader.run(className, ... rest) waits until all needed classes are loaded and initialized, and, in analogy to Java, simply invokes the static main method of the given class with the rest paramters.