Skip to main content

Start the server

The Chat Server API can be started using the Gradle wrapper or by running the compiled JAR directly.
./gradlew bootRun
This command will:
  • Compile the application if needed
  • Start the Spring Boot application
  • Enable hot reload with DevTools
  • Display startup logs in the console
After building the project, run the compiled JAR:
java -jar build/libs/server-0.0.1-SNAPSHOT.jar

With custom environment variables

export JWT_SECRET="your-secure-base64-secret"
./gradlew bootRun

Verify the server is running

1

Check the startup logs

When the server starts successfully, you should see output similar to:
Started APIServerApplication in X.XXX seconds
The application name is defined in application.properties:1 as “server”.
2

Check the default port

By default, Spring Boot applications run on port 8080. Look for this line in the logs:
Tomcat started on port 8080 (http)
3

Test the health endpoint

The server includes Spring Boot Actuator (build.gradle.kts:35). Test the health endpoint:
curl http://localhost:8080/actuator/health
Expected response:
{"status":"UP"}
4

Verify database creation

Check that the SQLite database file was created:
ls -la main.db
The file should exist in the directory where you started the server.

Access Swagger UI

The server includes SpringDoc OpenAPI documentation (build.gradle.kts:53-54) with an interactive Swagger UI.
The API documentation is configured in APIServerApplication.java:22-27 with the title “Chat Server API” and version from Configuration.SERVER_VERSION.

Open Swagger UI

Navigate to the following URL in your web browser:
http://localhost:8080/swagger-ui.html
Or use the alternative path:
http://localhost:8080/swagger-ui/index.html

Features available in Swagger UI

  • Interactive API documentation: View all available endpoints
  • Request/response schemas: See data models and validation rules
  • Try it out: Execute API requests directly from the browser
  • Authentication: Test endpoints with JWT tokens

View OpenAPI specification

Access the raw OpenAPI JSON specification:
http://localhost:8080/v3/api-docs

Stopping the server

# Press Ctrl+C in the terminal where the server is running

Troubleshooting

Port already in use

If you see an error like:
Web server failed to start. Port 8080 was already in use.
Solutions:
  1. Change the port: Create application.properties override or use command line:
    ./gradlew bootRun --args='--server.port=8081'
    
  2. Kill the existing process:
    # Linux/macOS
    lsof -ti:8080 | xargs kill -9
    
    # Windows
    netstat -ano | findstr :8080
    taskkill /PID <PID> /F
    

Database locked error

If you see:
SQLite database is locked
Solutions:
  1. Check for multiple server instances: Ensure only one server process is accessing the database
  2. Remove lock files: Delete main.db-shm and main.db-wal files (only when server is stopped)
  3. Verify WAL mode: The server configures WAL mode automatically via connection-init-sql in application.properties:8-12

JWT authentication errors

If authentication fails with token errors:
JWT signature does not match
Solutions:
  1. Verify JWT_SECRET: Ensure the environment variable is set correctly and is Base64-encoded
    echo $JWT_SECRET  # Linux/macOS
    echo %JWT_SECRET%  # Windows CMD
    
  2. Check token expiration: Tokens expire after 30 days (Configuration.java:15). Generate a new token by logging in again.
  3. Use the default secret: For development only, the server falls back to a default secret if JWT_SECRET is not set

Out of memory errors

If the server crashes with:
java.lang.OutOfMemoryError: Java heap space
Solutions:
  1. Increase heap size:
    # Using Gradle
    ./gradlew bootRun --args='-Xmx512m'
    
    # Using JAR
    java -Xmx512m -jar build/libs/server-0.0.1-SNAPSHOT.jar
    
  2. Adjust SQLite cache: Reduce the cache size in application.properties from -10000 to -5000 (5MB)

Connection refused errors

If external clients can’t connect:
Connection refused: localhost:8080
Solutions:
  1. Bind to all interfaces: Add to application.properties:
    server.address=0.0.0.0
    
  2. Check firewall settings: Ensure port 8080 is allowed through your firewall
  3. Verify server is running: Check the process is active:
    # Linux/macOS
    ps aux | grep APIServerApplication
    
    # Windows
    tasklist | findstr java
    

Schema validation errors

If you see Hibernate validation errors:
Schema-validation: missing table
Solutions:
  1. Delete the database: Remove main.db and restart (development only)
    rm main.db main.db-shm main.db-wal
    ./gradlew bootRun
    
  2. Change DDL mode: In application.properties, temporarily use create instead of update:
    spring.jpa.hibernate.ddl-auto=create
    
    Using create will drop all existing tables and data. Only use in development.

Enable debug logging

For detailed troubleshooting, enable debug logs:
./gradlew bootRun --args='--logging.level.org.uwgb.compsci330=DEBUG'

Production deployment

For production deployments:
1

Set secure environment variables

export JWT_SECRET=$(openssl rand -base64 64)
2

Build production JAR

./gradlew clean build -x test
3

Use production database path

Configure absolute path in application.properties:
spring.datasource.url=jdbc:sqlite:/var/lib/chatserver/production.db
4

Run as a service

Consider using systemd (Linux) or similar service managers to run the server as a background service.
Monitor the server using the Actuator endpoints at /actuator/metrics and /actuator/info.

Build docs developers (and LLMs) love