Class Loading
Klyn resolves classes through a deterministic search order. The rule is deliberately strict:
standard library classes are always resolved before application classes, so local files cannot
impersonate or shadow core klyn.* types.
When the runtime looks for a class source file, it checks these roots in order:
$KLYN_HOME/lib, the standard library root.- The directory containing the startup
.knfile passed toklyn. - Each directory passed through
-kpor--klasspath, from left to right. - Each directory listed in
$KLASSPATH, from left to right. - The current working directory, if it was not already added as the startup directory.
This order prevents an application or launch directory from replacing standard library
classes. For example, a local klyn/String.kn will not override the real
klyn.String implementation.
The startup directory is the folder that contains the script you launch, not necessarily the shell current directory.
cd ~/Klyn
klyn samples/gui/ClockSample.kn
In this example, Klyn searches ~/Klyn/samples/gui before explicit klasspath roots,
before $KLASSPATH
and before ~/Klyn. This keeps applications relocatable without making the current
directory more powerful than the application root.
Klasspath entries are source roots. A type declared in
package my.app.core must therefore be stored below
my/app/core within one of those roots. Klyn validates this correspondence and
rejects a mismatched declaration. A source without a package declaration remains in the
default package regardless of its physical directory.
Use -kp or --klasspath when an application depends on additional source roots
outside its startup directory. On Linux, entries are separated with :. On Windows,
entries are separated with ;.
klyn -kp "/opt/klyn-libs:/home/me/shared-klyn" app/Main.kn
klyn --klasspath "/opt/klyn-libs" app/Main.kn
For reproducible launch commands, prefer the explicit command-line option. Environment variables remain useful for developer shells and CI jobs that share a common dependency layout.
export KLASSPATH="/opt/klyn-libs:/home/me/shared-klyn"
klyn app/Main.kn
Klyn also accepts the historical KLYNPATH variable when KLASSPATH is not
defined, but new projects should use KLASSPATH.
Class lookup and object caching are separate concerns. Once a source file has been resolved,
the compiler reuses its cached .o file when that object is newer than the
corresponding .kn source. If the source changes, Klyn recompiles it automatically.
Continue with Coding Conventions before moving to the core syntax chapters.