Skip to content

Instantly share code, notes, and snippets.

@Charlie-robin
Created January 6, 2026 22:03
Show Gist options
  • Select an option

  • Save Charlie-robin/3055501f17e74108ad56890008aed93e to your computer and use it in GitHub Desktop.

Select an option

Save Charlie-robin/3055501f17e74108ad56890008aed93e to your computer and use it in GitHub Desktop.
Beechat Maven & Javalin Project Set up

Set up Beechat

Concise steps to convert the Beechat project into a Maven project using Javalin in IntelliJ.

Create the Server Module

  1. Open the project’s root directory in IntelliJ.
  2. Delete the existing server folder and the .gitkeep file.
  3. Go to File -> New -> New Module
    • Select Generators (Left sidebar) -> Maven Archetype
      • Name: server
      • Archetype: org.apache.maven.archetypes:maven-archetype-archetype
    • Create

Add Javalin Deps to pom.xml

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

Create Javalin WS Server

  1. Inside src/main create a java folder
  2. Create a Main inside src/main/java class 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment