Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Jump into Java microframeworks, Part 1

Matthew Tyson | Oct. 28, 2015
Go extra lightweight, with Java microframeworks Spark, Ninja, and Play

Next, select Existing Projects into Workspace, as shown in Figure 2:

Java Micro Frameworks, Part 1.
Figure 2. Eclipse project import, Step 2

Select Browse and choose the directory where your project is located. Recall that Maven created a directory based on your project name, which in my case is /micro-ninja. Select OK.

Java Micro Frameworks, Part 1.
Figure 3. Eclipse project import, Step 3

Your project should now appear in the main pane, already selected with a checkbox, as shown in Figure 4.

Java Micro Frameworks, Part 1.
Figure 4. Eclipse project import, Step 4

When you hit Finish, the fully formed Ninja project should import into your workspace. We'll follow these same steps to import the projects for Spark and Play later on.

Maven source and documentation

When it comes to automation, Maven is one of the greats. When using Maven to generate projects, I often use the following command to pull down the project's source and documentation, so that I can inspect them while coding: mvn eclipse:eclipse -DdownloadSources -DdownloadJavadocs.

When you crack open the Ninja project's navigation pane, you might wonder if you're really looking at a microframework. Ninja's curated set of open-source libraries places it in the category of a full-stack microframework.

A package of interest is Guice. Guice is an IOC (Inversion of Control) library for connecting application dependencies in a de-coupled style. If you're familiar with Spring, Guice performs the same role as Spring's core IOC library.

Dev mode

Drop back to the command-line for a moment, and run: mvn ninja:run. Now open your browser to localhost:8080. A simple app is already running; and moreover, it is hot-deploying your code.

You can set the port for dev mode with the command:

mvn ninja:run -ninja.port=9090

In the Project menu, make sure that Eclipse is set to "Build Project Automatically," as shown in Figure 5. When Eclipse compiles your classes, Ninja will watch for them and make the changes live. Ninja also watches the static resources directory.

Java Micro Frameworks, Part 1.
Figure 5. Eclipse project import, Step 5

To be sure it's working, let's run a quick test. Open the file /src/main/java/conf/, and make the change shown in Listing 1.

Listing 1.


# This file is utf-8

header.title=Hello, JavaWorld!

header.home=BAM!, JavaWorld!


Reload the page and you'll see the new message: "Hello, JavaWorld!" Ninja's built-in internationalization support and template system inserted it automatically. We'll take a closer look at Ninja's template library in the next section.


Previous Page  1  2  3  4  5  6  7  8  9  10  Next Page 

Sign up for CIO Asia eNewsletters.