=== Development

The `jooby run` tool provides a "hot reload" experience by restarting your application automatically whenever code changes are detected, without exiting the JVM. This makes Java and Kotlin development feel as fast and iterative as a scripting language.

The tool leverages https://jboss-modules.github.io/jboss-modules/manual[JBoss Modules] to efficiently reload application classes. It is available as both a Maven and a Gradle plugin.

==== Usage

1) Add the build plugin:

.pom.xml
[source, xml, role = "primary", subs="verbatim,attributes"]
----
<plugins>
  <plugin>
    <groupId>io.jooby</groupId>
    <artifactId>jooby-maven-plugin</artifactId>
    <version>{joobyVersion}</version>
  </plugin>
</plugins>
----

.build.gradle
[source, gradle, role = "secondary", subs="verbatim,attributes"]
----
plugins {
  id "application"
  id "io.jooby.run" version "{joobyVersion}"
}
----

2) Configure the Main Class:

.pom.xml
[source, xml, role = "primary"]
----
<properties>
  <application.class>myapp.App</application.class>
</properties>
----

.build.gradle
[source, gradle, role = "secondary"]
----
mainClassName = "myapp.App"
----

3) Launch the Application:

.Maven
[source, bash, role = "primary"]
----
mvn jooby:run
----

.Gradle
[source, bash, role = "secondary"]
----
./gradlew joobyRun
----

==== Compilation and Restart

* **Source Files (`.java`, `.kt`):** Changing a source file triggers an incremental compilation request. If the compilation succeeds, the application restarts automatically.
* **Configuration Files (`.conf`, `.properties`):** Changes to these files trigger an immediate application restart without a compilation step.
* **Compilation Errors:** Any errors during the build process are printed directly to the console by Maven or Gradle.

[NOTE]
====
For **Eclipse** users: The plugin detects the `.classpath` file in your project directory. If found, the plugin's internal compiler is disabled, letting Eclipse handle the compilation while the plugin focuses on the restart logic.
====

==== Options

Below are the available configuration options with their default values:

.pom.xml
[source, xml, role = "primary", subs="verbatim,attributes"]
----
<configuration>
  <mainClass>${application.class}</mainClass>
  <restartExtensions>conf,properties,class</restartExtensions>
  <compileExtensions>java,kt</compileExtensions>
  <port>8080</port>
  <waitTimeBeforeRestart>500</waitTimeBeforeRestart>
  <useSingleClassLoader>false</useSingleClassLoader>
</configuration>
----

.build.gradle
[source, gradle, role = "secondary", subs="verbatim,attributes"]
----
joobyRun {
  mainClassName = "${mainClassName}"                               // <1>
  restartExtensions = ["conf", "properties", "class"]              // <2>
  compileExtensions = ["java", "kt"]                               // <3>
  port = 8080                                                      // <4>
  waitTimeBeforeRestart = 500                                      // <5>
  useSingleClassLoader = false                                     // <6>
}
----

<1> The application's entry point (Main class).
<2> Extensions that trigger an immediate restart.
<3> Extensions that trigger a compilation followed by a restart.
<4> The local development port.
<5> The delay (in milliseconds) to wait after the last file change before restarting. Default is `500ms`.
<6> If `true`, Jooby uses a single "fat" classloader. Set this to `true` if you encounter strange reflection or class-loading errors in complex projects. Since 3.x, Jooby uses a modular classloader by default for faster restarts and lower memory usage.

==== Testing with Classpath

To run the application while including the `test` scope/source set in the classpath, use the following commands:

* **Maven:** `mvn jooby:testRun`
* **Gradle:** `./gradlew joobyTestRun`
