Quick overview - MTDdk/jawn GitHub Wiki
Typical structure of a jawn project
(See jawn-simple)
\-- src
\-- main
+-- java
| \-- app
| +-- controllers
| | +-- IndexController.java (standard)
| | +-- MovieController.java
| | \-- SomeController.java
| +-- models
| | \-- Movie.java
| \-- SimpleMain.java (extends Jawn)
\-- resources
+-- jawn.properties
\-- webapp
+-- css
+-- images
+-- js
+-- favico.ico
\-- views
+-- index
| +-- index.html.st
| \-- redirect.st (referenced by action)
+-- movie
| \-- list.st
+-- some
| \-- index.st
\-- index.html.st (default layout)
Entry point
public class NoConfigurationMain extends Jawn {
public static void main(String[] args) throws Exception {
Jawn.run(); // creates a new server and starts it
}
}
Instance of Jawn
public class SimpleMain extends Jawn {
// implicit constructor
{
env(Modes.DEV);
onStartup(() -> System.out.println("My app has started up!"));
onShutdown(() -> System.out.println("Closing down"));
}
public static void main(String[] args) throws Exception {
run(SimpleMain::new); // starts the server
}
}
Configuration
Most configuration is done in code of the entry point - the class extending
In the structure above, that would be SimpleMain.java
.
This class will most commonly be placed in the root of the project for quick overview of the starting/main class.
Controllers
The controller part of MVC, always located in the package structure app.controllers
.
The naming convention is to always end a controller with Controller and extending ApplicationController
.
This is what the framework is looking for.
Models
The model part of MVC, normally placed in the app.models
. While this is not a requirement, it is, however, encouraged convention.
Contrary to the configuration and controllers, the placement of models are not dictated by the framework.
Views
The view part of MVC, ordered in subfolders within the WEB-INF/views
named as their respective controllers.
It is essential for the naming of controllers and their corresponding views to be named identically as the view is looked up
on basis of the name of the controller.
webapp
Static content - subfolders of Every direct subfolder or file within webapp
(outside of WEB-INF
) is automatically exposed by the web server.
This means that images in the images
folder, without further ado, can be found on:
http://host:port/images/something.jpg
And so on for every other file or folder as well.
The folders in the example structure are only often used folders, but can be omitted and others can be added.
Because of this dynamic loading of static content, any controller can not be named likewise as a folder of static content. If any name-clashing occurs, the static content will be given precedence.