Java Vanilla
Overview
Java Vanilla is a plain Java project using only the standard library and a lightweight HTTP server. It provides a clean starting point for building web applications and REST APIs without any framework overhead.
Quick Start
Create Repository from Template
On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Java Vanilla template from the dropdown, enter a repository name and subdomain, then click "Create Repository".
Clone Your Repository
git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
Build the Project
mvn clean package
Run the Application
java -jar target/app.jar
Server runs on http://localhost:8080 by default.
Push Your Changes
git add .
git commit -m "Initial setup"
git push origin main
Local Development with Docker
If you don't have Java or Maven installed locally, you can use Docker to build and run your project.
Running Commands with Docker
# Build the project
docker run --rm -v $(pwd):/app -w /app maven:3-eclipse-temurin-21 mvn clean package
# Run the application
docker run --rm -v $(pwd):/app -w /app -p 8080:8080 eclipse-temurin:21 java -jar target/app.jar
Project Structure
├── src/
│ └── main/
│ └── java/
│ └── com/example/
│ ├── App.java # Entry point & HTTP server
│ ├── handlers/ # Request handlers
│ └── models/ # Data models
├── pom.xml # Maven dependencies
└── Dockerfile # Docker config
Common Tasks
Creating an HTTP Handler
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import java.io.OutputStream;
public class UsersHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
String response = "{\"message\": \"Hello from Java!\"}";
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, response.length());
try (OutputStream os = exchange.getResponseBody()) {
os.write(response.getBytes());
}
}
}
Database Connection with JDBC
import java.sql.*;
String url = "jdbc:mysql://db.<session-domain>:3306/<username>";
Connection conn = DriverManager.getConnection(url, "username", "password");
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
stmt.setInt(1, userId);
ResultSet rs = stmt.executeQuery();
Useful Commands
mvn clean package
Build the project
java -jar target/app.jar
Run the application
mvn dependency:tree
Show dependency tree
Troubleshooting
java.sql.SQLException: Access denied
Solution: Check your JDBC connection URL, username, and password match the credentials from your dashboard.
Port 8080 already in use
Solution: Change the port in your App.java or stop the other process using port 8080.
ClassNotFoundException for JDBC driver
Solution: Ensure the MySQL JDBC driver is included in your pom.xml dependencies and run mvn clean package again.