== Hot Reload

The `jooby run` tool allows to restart your application on code changes without exiting the JVM.

This feature is also known as hot reload/swap. Makes you feel like coding against a script 
language where you modify your code and changes are visible immediately.
  
The tool uses the https://jboss-modules.github.io/jboss-modules/manual[JBoss Modules] library
that effectively reload application classes.

For now `jooby run` is available as Maven and Gradle plugins.

=== Usage

1) Add 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, groovy, role = "secondary", subs="verbatim,attributes"]
----
buildscript {

  repositories {
    mavenCentral()
  }

  dependencies {
    classpath "io.jooby:jooby-gradle-plugin:{joobyVersion}"
  }
}

apply plugin: "application"
apply plugin: "jooby"
----

2) Set main class

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

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

3) Run application

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

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

=== Compilation & Restart

Changing a `java` or `kotlin` file triggers a compilation request. Compilation is executed by 
Maven/Gradle using an incremental build process.

If compilation succeed, application is restarted.

Compilation errors are printed to the console by Maven/Gradle.

Changing a `.conf`, `.properties` file triggers just an application restart request. They don't trigger
a compilation request.

Compiler is enabled by default, except for Eclipse users. Plugin checks for `.classpath` file in
project directory, when found plugin compiler is OFF and let Eclipse compiles the code. 

=== Options

The next example shows all the available options with their default values:

.pom.xml
[source, xml, role = "primary", subs="verbatim,attributes"]
----
<plugins>
  ...
  <plugin>
    <groupId>io.jooby</groupId>
    <artifactId>jooby-maven-plugin</artifactId>
    <version>{joobyVersion}</version>
    <configuration>
      <mainClass>${application.class}</mainClass>                  <1>
      <restartExtensions>conf,properties,class</restartExtensions> <2>
      <compileExtensions>java,kt</compileExtensions>                  <3>
      <port>8080</port>                                            <4>
    </configuration>
  </plugin>
  ...
</plugins>
----

.build.gradle
[source, groovy, role = "secondary", subs="verbatim,attributes"]
----
buildscript {
  
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath "io.jooby:jooby-gradle-plugin:{joobyVersion}"
  }
}

apply plugin: "application"
apply plugin: "jooby"

joobyRun {
  mainClass = "${mainClassName}"                                   <1>
  restartExtensions = ["conf", "properties", "class"]              <2>
  compileExtensions =  ["java", "kt"]                               <3>
  port = 8080                                                      <4>
}
----

<1> Application main class
<2> Restart extensions. A change on these files trigger a restart request.
<3> Source extensions. A change on these files trigger a compilation request, followed by a restart request.
<4> Application port

