-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
This guide will help you get up and running with Java Server Interface quickly.
- Java 11 or higher (tested with Java 17+)
- Basic understanding of Java and OOP concepts
- Familiarity with client-server architecture (helpful but not required)
Use the following command to clone the GitHub repository inside the jsi root package folder:
git clone https://github.com/LucaPrevi0o/JavaServerInterface.git jsi
cd jsiJSI includes a custom build script (jmake) that works without Maven or Gradle:
# Compile all sources
./jmake
# Compile and run the default Main class
./jmake run
# Compile and run a specific class
./jmake run -n MyServer
# Build an executable JAR
./jmake jar
# Clean build artifacts
./jmake cleanCreate a file MyFirstServer.java:
import jsi.connection.http.*;
import jsi.connection.http.response.HttpResponseType;
public class MyFirstServer extends HttpServer {
public MyFirstServer(int port) {
super(port);
}
@Route(path = "/")
public HttpResponse home(HttpRequest request) {
String html = "<html><body>" +
"<h1>Welcome to JSI!</h1>" +
"<p>Your first server is running.</p>" +
"</body></html>";
return createHtmlResponse(HttpResponseType.OK, html);
}
@Route(path = "/about")
public HttpResponse about(HttpRequest request) {
String html = "<html><body>" +
"<h1>About</h1>" +
"<p>Built with Java Server Interface</p>" +
"</body></html>";
return createHtmlResponse(HttpResponseType.OK, html);
}
public static void main(String[] args) {
System.out.println("Starting server on port 8080...");
new MyFirstServer(8080).start();
}
}Compile and run:
./jmake run -n MyFirstServerAccess in browser:
-
http://localhost:8080/- Home page -
http://localhost:8080/about- About page
JSI can serve static HTML files directly:
import jsi.connection.http.*;
import jsi.connection.http.response.HttpResponseType;
public class StaticFileServer extends HttpServer {
public StaticFileServer(int port) {
super(port);
}
// Serve static file automatically
@Route(path = "/", staticResource = "static/index.html")
public HttpResponse home(HttpRequest request) {
return null; // File served automatically
}
// Mix static and dynamic routes
@Route(path = "/api/status")
public HttpResponse status(HttpRequest request) {
String json = "{\"status\": \"running\", \"version\": \"1.0\"}";
return createJsonResponse(HttpResponseType.OK, json);
}
public static void main(String[] args) {
new StaticFileServer(8080).start();
}
}Create a simple database server with JSON persistence:
import jsi.connection.database.*;
import jsi.connection.database.json.JsonStorageEngine;
import jsi.connection.database.mysql.MySqlServer;
public class MyDatabaseServer {
public static void main(String[] args) throws Exception {
// Create storage engine with path to database directory
StorageEngine storage = new JsonStorageEngine("./database");
// Create database engine
DatabaseEngine engine = new DatabaseEngine(storage);
// Start MySQL-compatible server on port 3306
DatabaseServer server = new MySqlServer(3306, engine);
System.out.println("Database server started on port 3306");
server.start();
}
}Now that you have a basic server running, explore:
- Architecture Overview - Understand how JSI layers work together
-
Core Abstractions - Learn about
Server,Client,Request,Response - HTTP Server - Deep dive into HTTP routing and request handling
- Database Server - Build database-backed applications
- Extensibility Guide - Create your own protocols
@Route(path = "/greet")
public HttpResponse greet(HttpRequest request) {
String name = (String) request.getParameter("name");
if (name == null) name = "Guest";
String html = "<h1>Hello, " + name + "!</h1>";
return createHtmlResponse(HttpResponseType.OK, html);
}Access with: http://localhost:8080/greet?name=Alice
@Route(path = "/divide")
public HttpResponse divide(HttpRequest request) {
try {
int a = Integer.parseInt((String) request.getParameter("a"));
int b = Integer.parseInt((String) request.getParameter("b"));
int result = a / b;
return createHtmlResponse(HttpResponseType.OK,
"<h1>Result: " + result + "</h1>");
} catch (Exception e) {
return createHtmlResponse(HttpResponseType.BAD_REQUEST,
"<h1>Error: Invalid parameters</h1>");
}
}Override handleNotFound() in your server class:
@Override
protected HttpResponse handleNotFound(Request request) {
String html = "<html><body>" +
"<h1>404 - Page Not Found</h1>" +
"<p>The page you're looking for doesn't exist.</p>" +
"<a href='/'>Go Home</a>" +
"</body></html>";
return createHtmlResponse(HttpResponseType.NOT_FOUND, html);
}If you get a "port already in use" error, either:
- Stop the existing process using that port
- Change the port number in your constructor
Ensure static file paths are relative to the project root:
project/
├── static/
│ └── index.html
└── MyServer.java
Use path: static/index.html
Make sure you're in the project root directory when running ./jmake.
- Architecture Overview - Understand the layered design
- HTTP Server - Complete HTTP server guide
- Core Abstractions - Base classes and interfaces
- Extensibility Guide - Build custom protocols
Questions? Check the main README or explore the source code.
JSI - Java Server Interface | Educational Server Framework | Zero Dependencies
Home • Getting Started • Architecture • Source Code
Made for learning | Report Issues • Discussions
Last updated: December 2025 | JSI v1.0
HTTP Development
Database Development
Custom Protocols