Your first Wisdom project

Important
Be sure you have a recent version of Maven (3.2.1+).

Create a Wisdom project

Wisdom is based on the Apache Maven build tools. However don’t worry, Wisdom makes it easy. However, first, be sure you have Maven installed.

Once installed, you can create your first Wisdom project by launching:

mvn org.wisdom-framework:wisdom-maven-plugin:0.6.1:create \
 -DgroupId=YOUR_GROUPID \
 -DartifactId=YOUR_ARTIFACTID \
 -Dversion=1.0-SNAPSHOT

On Windows use:

mvn.bat org.wisdom-framework:wisdom-maven-plugin:0.6.1:create -DgroupId="YOUR_GROUPID" -DartifactI
d="YOUR_ARTIFACTID" -Dversion="YOUR_VERSION"
Tip
You can also customize the generated package with -Dpackage=org.acme.wisdom

Once generated, you can already run your wisdom application. Navigate to the generated folder, and launch:

mvn wisdom:run

Then, open your browser to: http://localhost:9000.

That’s it you have your first Wisdom application.

Using the Maven Archetype

This section is only for Maven users willing to use an archetype. The very same project can be generated using the wisdom-default-project-archetype:

mvn org.apache.maven.plugins:maven-archetype-plugin:generate \
 -DarchetypeArtifactId=wisdom-default-project-archetype \
 -DarchetypeGroupId=org.wisdom-framework \
 -DarchetypeVersion=0.6.1 \
 -DgroupId=YOUR_GROUPID \
 -DartifactId=YOUR_ARTIFACTID \
 -Dversion=1.0-SNAPSHOT

The archetype can be used from your IDE to generate a new project directly.

What was generated?

The previous commands have generated a set of folders. Following the Maven conventions, all files are placed in the src directory, while the generated artifacts are in target.

The src/main directory is structured as follows:

  • src/main/java contains the Java sources of your application

  • src/main/resources contains the assets and templates included in your application package

  • src/main/configuration contains the configuration file (application, runtime, logger…)

  • src/main/assets contains assets that are copied to Wisdom but not included in application package

  • src/main/templates contains assets that are copied to Wisdom but not included in application package

The src/test directory contains the tests (unit and integration tests).

You first controller

The generated application contains a controller. A controller is a Wisdom component containing actions, i.e. methods called using HTTP requests.

package sample;

import org.wisdom.api.DefaultController;
import org.wisdom.api.annotations.*;
import org.wisdom.api.http.HttpMethod;
import org.wisdom.api.http.Result;

@Controller                                                  (1)
public class WelcomeController extends DefaultController {   (2)

    @View("welcome")
    private Template welcome;

    @Route(method = HttpMethod.GET, uri = "/")               (3)
    public Result welcome() {
        return ok(render(welcome));                          (4)
    }

}
  1. First, declare the Java class as Wisdom’s controller

  2. Extend DefaultController to inherit from the useful method

  3. Specify the HTTP route connected to your action method

  4. The body of your action, returning a Result object

In the previous example, the controller is using a template (welcome), but things can be much simpler:

 /**
  * Your first Wisdom Controller.
  */
 @Controller                                                    (1)
 public class SampleController extends DefaultController {      (2)

     @Route(method = HttpMethod.GET, uri = "/hello")            (3)
     public Result hello() {
         return ok("hello Wisdom !");                           (4)
     }
 }
  1. First, declare the Java class as Wisdom’s controller

  2. Extend DefaultController to inherit from the useful method

  3. Specify the HTTP route connected to your action method

  4. The body of your action, returning a Result object

Wisdom API and Maven Plugin

  • The Wisdom JavaDoc is available on the API page.

  • The Wisdom-Maven-Plugin goals and configuration are described on the Maven Site.