Concise steps to convert the Beechat project into a Maven project using Javalin in IntelliJ.
- Open the project’s root directory in IntelliJ.
- Delete the existing server folder and the .gitkeep file.
- Go to File -> New -> New Module
- Select Generators (Left sidebar) -> Maven Archetype
- Name: server
- Archetype: org.apache.maven.archetypes:maven-archetype-archetype
- Create
- Select Generators (Left sidebar) -> Maven Archetype
Add the following dependencies inside the <project> tag of the generated pom.xml:
<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin-bundle</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>Update the .gitignore
# Maven target directory
target/
# IntelliJ IDEA project files
.idea/
*.iml
# Logs
*.log
# OS-specific files
.DS_Store
Thumbs.db
# Build output
out/
# Temporary files
*.tmp
*.swp
# Java-specific
*.class
# Generated files
*.jar
*.war
*.ear
# IntelliJ caches
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# IntelliJ plugin-specific
.idea/**/gradle.xml
.idea/**/libraries
# Ignore compiled test results
test-output/
# Ignore any local environment configs
.env- Inside
src/maincreate ajavafolder - Create a
Maininsidesrc/main/javaclass and set up the Javalin application ready to work with websockets.
import io.javalin.Javalin;
import java.time.Duration;
public class Main {
public static void main(String[] args) {
Javalin app = Javalin.create(javalinConfig -> {
// Modifying the WebSocketServletFactory to set the socket timeout to 300 seconds
javalinConfig.jetty.modifyWebSocketServletFactory(jettyWebSocketServletFactory ->
jettyWebSocketServletFactory.setIdleTimeout(Duration.ofSeconds(300))
);
});
app.ws("/", wsConfig -> {
// WS Handlers
wsConfig.onConnect((connectContext) -> {
System.out.println("Connected: " + connectContext.sessionId());
});
wsConfig.onMessage((messageContext) -> {
System.out.println("Message: " + messageContext.sessionId());
});
wsConfig.onClose((closeContext) -> {
System.out.println("Closed: " + closeContext.sessionId());
});
wsConfig.onError((errorContext) -> {
System.out.println("Error: " + errorContext.sessionId());
});
});
app.start(5001);
}
}Press the green Run button to start the application.
Open the client directory, right‑click index.html, and select Open in → Browser → Default.
Check the browser console and the IntelliJ terminal for logs showing a connection.