Getting Started
Creating a new Project
We use Maven Archetypes to generate a template for you to get started.
First, create a directory called GLProjects:
$ mkdir GLProjects
$ cd GLProjectsNext, run the following command to create a new starter project:
$ mvn archetype:generate -DarchetypeGroupId=com.ociweb -DarchetypeArtifactId=greenlighter -DarchetypeVersion=1.0.2You will then be prompted to fill out some information:
Define value for property 'groupId': com.ociweb
Define value for property 'artifactId': Hello
Define value for property 'version' 1.0.0: :
Define value for property 'package' com.ociweb: :
Define value for property 'mainClass': RestServerHit "Y" to finish generating your new project.
This will generate a new GreenLightning project for us to start coding. Open up the project in your favorite IDE (such as IntelliJ IDEA or Eclipse) and navigate to the src/main/java/com.ociweb folder:
GreenLightning.java- This file is responsible for spinning up a new GreenLightning runtime and can be ignored for the rest of this tutorial.RestServer.java- This is the main file we will work with. It will setup our HTTP server, connect behaviors and routes, and configure connection settings.HelloField.java- This will contain enums required for field identification.HelloStruct.java- This will contain enums for route identification.
Setting up a HTTP Server
GreenLighting allows you to use a lot of different servers - you're not just limited to HTTP. In this example, we will be using HTTP, so we need to specify and create our HTTP 1.x server.
Open up RestServer.java. It should look something like this:
package com.ociweb;
import com.ociweb.gl.api.GreenFramework;
import com.ociweb.gl.api.GreenApp;
import com.ociweb.gl.api.GreenRuntime;
public class RestServer implements GreenApp {
@Override
public void declareConfiguration(GreenFramework builder) {
//define your features here
}
@Override
public void declareBehavior(GreenRuntime runtime) {
//register your behaviors here
}
}