Getting Started
This page provides a brief intro to the ktpack command line tool.
We will create a new project, build the source code, and run the compiled program.
Create a new project with the new command:
By default, the --bin flag is used to create a binary program.
Alternatively the --lib flag can be used to create a library.
The command generated two files:
$ cd hello_world
$ tree .
.
├── pack.toml
└── src
└── common
└── kotlin
└── main.kt
1 directory, 2 files
This is a basic, yet fully functional Ktpack project.
The project is described in pack.toml:
The pack.toml Manifest contains all the metadata required to operate a Ktpack project.
In src/common/kotlin/main.kt we have this program:
The source file can be compiled into a binary with the build command:
To run the executable we compiled:
Note: the linux_x64 directory could also be macosx_[x64|arm64] or mingw_x64 based on your operating system
Alternatively we can use the run command:
$ ktpack run
Compiling hello_world v1.0.0 (/users/developer/hello_world)
Running 'out/linux_x64/debug/bin/hello_world.exe'
Hello, World!
To build or run our program for a different target, use the --target or -t option with the build or run
commands:
$ ktpack run --target jvm
Compiling hello_world v1.0.0 (/users/developer/hello_world)
Running 'out/jvm/debug/bin/hello_world.jar'
Hello, World!
$ ktpack run --target js_node
Compiling hello_world v1.0.0 (/users/developer/hello_world)
Running 'out/js_node/debug/bin/hello_world.js'
Hello, World!
For the js_browser target, an HTTP Server is started which provides your program at the URL: