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>2.4.0</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>2.4.0</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) {
        Javalin app = Javalin.create().start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}
import io.javalin.Javalin

fun main(args: Array<String>) {
    val app = Javalin.create().start(7000)
    app.get("/") { ctx -> ctx.result("Hello World") }
}
// You can wrap the main function
// in a Kotlin object

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>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

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

If IntelliJ says Method references are not supported at this language level, press alt + enter
and choose Set language level to 8 - Lambdas, type annotations, etc.*

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>2.4.0</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) {
        Javalin app = Javalin.create().start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}
import io.javalin.Javalin

fun main(args: Array<String>) {
    val app = Javalin.create().start(7000)
    app.get("/") { ctx -> ctx.result("Hello World") }
}
// You can wrap the main function
// in a Kotlin object

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>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</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!