Skip to content

Attaching and running the JVM Agent with your Kotlin application

Version Support

The instructions below apply to Kotlin v1.5 and higher.


Before running the app with the agent, make sure you have:

Running the Lightrun agent

For Kotlin v1.6 and higher:

  1. Compile your application
kotlinc <your-main>.kt -include-runtime -d myapp.jar
  1. Run the application with the Java agent
java -agentpath:<path-to-agent>/ -jar myapp.jar

For Kotlin v1.5 you might get "no main manifest attribute". You can instead put the kotlin-stdlib in the classpath:

  1. Compile your application
kotlinc <your-main>.kt
  1. Run the application with the Java agent and kotlin-stdlib in the classpath
java -cp <path-to-kotlin>/kotlin-stdlib/1.4.20/kotlin-stdlib-1.4.20.jar:. -agentpath:<path-to-agent>/agent/ <your-main>


Like in Java, you can cause all launched Java processes automatically to be attached to an agent with the JAVA_OPTS environment variable.
Enter the following command:

export JAVA_OPTS=-agentpath:<path-to-agent>/


Kotlin expressions are limited:

  • All functions in the expression should be converted to their Java equivalent. For example, (pow -> Math.pow).
  • Expressions with Kotlin ranges and Coroutines are not supported.

Last update: May 18, 2022