IDE Guides
- Instructions for IntelliJ IDEA
- Instructions for Eclipse
- Instructions for VS Code
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.7.0</version>
</dependency>
</dependencies>
</project>
Instructions for IntelliJ IDEA
- Click
Fileand selectNew project... - Select
Mavenon the left hand menu and clickNext - 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.7.0</version>
</dependency>
</dependencies>
Finally, paste the Javalin “Hello World” snippet into a new file, HelloWorld.java:
- Java
- Kotlin
import io.javalin.Javalin;
void main() {
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 packageshould fix the issue.
Instructions for Eclipse
- Click
Fileand selectNewthenOther... - Expand
Mavenand selectMaven Project, then clickNext - Check the
Create a simple projectcheckbox and clickNext - Enter GroupId, ArtifactId, Verison, and Name, and click
Finish - Open the pom.xml file and click the
pom.xmltab. Paste the Javalin dependency
<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>6.7.0</version>
</dependency>
</dependencies>
Finally, paste the Javalin “Hello World” snippet into a new file, HelloWorld.java:
- Java
- Kotlin
import io.javalin.Javalin;
void main() {
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>
Depending on your version of eclipse, you might have to
Right click on your projectselectMaventhenUpdate Project
Now everything should be ready for you to run your application. Enjoy!
Instructions for VS Code
Prerequisites
Before creating a Maven project, ensure you have the Extension Pack for Java installed. This extension pack includes essential Java development tools and Maven support. Install it from the VS Code Marketplace or by searching for “Extension Pack for Java” in the Extensions view (Ctrl+Shift+X / Cmd+Shift+X).
Creating a New Maven Project
- Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) - Type
Java: Create Java Projectand select it - Select
Mavenas the project type - Select
maven-archetype-quickstartas the archetype - Select the latest version of the archetype
- Enter the GroupId (e.g.,
com.mygroup) - Enter the ArtifactId (e.g.,
my-javalin-project) - Select a folder to create the project in
- When prompted in the terminal:
- Press
Enterto accept the default version (1.0-SNAPSHOT) - Type
Yand pressEnterto confirm the properties configuration
- Press
⚠ macOS/Linux Users: If you encounter errors with the Maven wrapper (
mvnw), ensure Maven is installed on your system (see Prerequisites above). The Java extension will automatically detect and use the system-installed Maven.
Adding Javalin Dependency
Open the generated pom.xml file and add the Javalin dependency inside the <dependencies> section:
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>6.7.0</version>
</dependency>
Your <dependencies> section should now include both JUnit (added by the archetype) and Javalin.
Configuring Java Version
Update the maven-compiler-plugin configuration in your pom.xml to use Java 11 (or higher):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
Creating the Application
The archetype creates a package structure (e.g., com.example) based on your GroupId. You can either modify the generated App.java or create a new HelloWorld.java in the same package directory (e.g., src/main/java/com/example/):
package com.example; // use your GroupId as the package name
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);
}
}
💡 Note: We use the traditional
public static void main(String[] args)syntax for better compatibility with VS Code’s debugger. Java 21’s implicit class syntax (void main()) may cause issues with debugging.
Running the Application
There are several ways to run your Javalin application:
-
Using the Run button: Open
HelloWorld.javaand click theRunbutton (▶) above themainmethod. This CodeLens feature is provided by the Java extension and works out of the box. -
Using Debug Configuration (F5): For a more configurable debugging setup, create
.vscode/launch.json:{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Run HelloWorld", "request": "launch", "mainClass": "com.example.HelloWorld", "projectName": "my-javalin-project" } ] }💡 Note: Update
mainClassto match your package and class name (e.g.,com.mygroup.HelloWorld), andprojectNameto match your project’s ArtifactId frompom.xml.Then press
F5or go toRun→Start Debugging. VS Code’s Java extension handles compilation automatically.
💡 Tip: If VS Code doesn’t recognize the Javalin imports, try:
- Right-click on
pom.xml→ selectMaven→Reload project- Or run
Maven: Reload Projectsfrom the Command Palette (Ctrl+Shift+P/Cmd+Shift+P)- If issues persist, run
Java: Clean Java Language Server Workspacefrom the Command Palette
⚠ Troubleshooting “ClassNotFoundException”: If you see
Error: Could not find or load main class HelloWorld:
- Right-click on
pom.xml→ selectMaven→Reload projectto ensure dependencies are resolved- Run
Java: Clean Java Language Server Workspacefrom the Command Palette- Reload VS Code window:
Ctrl+Shift+P/Cmd+Shift+P→Developer: Reload Window
Now everything should be ready for you to run your application. Enjoy!