All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.getting-started.html Maven / Gradle / Ivy



    
        
        
        
        XpressJ.com Lightweight Sinatra/Express.js inspired framework for web applications in Java
        
        
        
    
    
        Skip to main content
        
        

        

Getting started

How to build your first application with XpressJ

For more detailed information on available settings and options please check Documentation.

"Hello World!" application

It is recommended to use XpressJ with Maven to simplify dependency management. Create basic Maven project with IDE of your choice and add following dependencies to your pom.xml:

<dependency>
    <groupId>com.xpressj</groupId>
    <artifactId>xpressj</artifactId>
    <version>0.7.0</version>
</dependency>
<dependency>
    <groupId>com.xpressj</groupId>
    <artifactId>xpressj-jetty</artifactId>
    <version>0.7.0</version>
</dependency>

Then create main class for our application called HelloWorld.java:

import xpressj.Configuration;
import xpressj.XpressJ;
import xpressj.route.Route;
import xpressj.server.Request;
import xpressj.server.Response;

public class HelloWorld {
    public static void main (String[] args) {
        Configuration configuration = new Configuration();
        XpressJ app = new XpressJ(configuration);

        app.get("/", new Route() {
            @Override
            public void handle(Request request, Response response) {
                response.send("Hello World!");
            }
        });
    }
}

Then run your application. In console output your should see following:

** Configured to listen on 0.0.0.0:8080
** XpressJ has started ...

That means server has successfully started and listens to port 8080 on local interfaces. Now you can open in your browser http://localhost:8080/ which should display string Hello World!. Congratulations, you just finished your first application using XpressJ!





© 2015 - 2025 Weber Informatics LLC | Privacy Policy