IDE Guides

- Instructions for IntelliJ IDEA
- Instructions for Eclipse

About Maven

Maven is a build automation tool used primarily for Java projects. It addresses two aspects of building software: First, it describes how software is built, and second, it describes its dependencies.

Maven projects are configured using a Project Object Model, which is stored in a pom.xml-file.

Here’s a minimal example:

<project>
    <!-- model version - always 4.0.0 for Maven 2.x POMs -->
    <modelVersion>4.0.0</modelVersion>

    <!-- project coordinates - values which uniquely identify this project -->
    <groupId>com.mygroup</groupId>
    <artifactId>my-javalin-project</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <!-- library dependencies -->
    <dependencies>
        <dependency>
            <groupId>io.javalin</groupId>
            <artifactId>javalin</artifactId>
            <version>6.1.3</version>
        </dependency>
    </dependencies>
</project>

Instructions for IntelliJ IDEA

  • Click File and select New project...
  • Select Maven on the left hand menu and click Next
  • Enter GroupId, ArtifactId and Version, and click Next
  • Give your project a name and click Finish:
  • Paste the Javalin dependency into the generated pom.xml. If prompted, tell IntelliJ to enable auto-import.
<dependencies>
    <dependency>
        <groupId>io.javalin</groupId>
        <artifactId>javalin</artifactId>
        <version>6.1.3</version>
    </dependency>
</dependencies>

Finally, paste the Javalin “Hello World” snippet into a new file, HelloWorld.java:

  • Java
  • Kotlin
import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        var app = Javalin.create(/*config*/)
            .get("/", ctx -> ctx.result("Hello World"))
            .start(7070);
    }
}
import io.javalin.Javalin

fun main() {
    val app = Javalin.create(/*config*/)
        .get("/") { ctx -> ctx.result("Hello World") }
        .start(7070)
}

Depending on your setup, you might need to explicitly set the language level to Java 11. This can be done in the in the pom.xml. Add the following snippet:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Now everything should be ready for you to run your application. Enjoy!

⚠ Note: Due to a bug in the IntelliJ integration with Maven there is a known issue where intelliJ will show an error in the code editor, if this happens, refreshing the project and running the goal mvn clean package should fix the issue.

Instructions for Eclipse

  • Click File and select New then Other...
  • Expand Maven and select Maven Project, then click Next
  • Check the Create a simple project checkbox and click Next
  • Enter GroupId, ArtifactId, Verison, and Name, and click Finish
  • Open the pom.xml file and click the pom.xml tab. Paste the Javalin dependency
<dependencies>
    <dependency>
        <groupId>io.javalin</groupId>
        <artifactId>javalin</artifactId>
        <version>6.1.3</version>
    </dependency>
</dependencies>

Finally, paste the Javalin “Hello World” snippet into a new file, HelloWorld.java:

  • Java
  • Kotlin
import io.javalin.Javalin;

public class HelloWorld {
    public static void main(String[] args) {
        var app = Javalin.create(/*config*/)
            .get("/", ctx -> ctx.result("Hello World"))
            .start(7070);
    }
}
import io.javalin.Javalin

fun main() {
    val app = Javalin.create(/*config*/)
        .get("/") { ctx -> ctx.result("Hello World") }
        .start(7070)
}

Depending on your setup, you might need to explicitly set the language level to Java 8. This can be done in the in the pom.xml. Add the following snippet:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Depending on your version of eclipse, you might have to

  • Right click on your project select Maven then Update Project

Now everything should be ready for you to run your application. Enjoy!