Skip to content

Commit 77516bf

Browse files
committed
apt: usage documentation
1 parent fca01ce commit 77516bf

File tree

6 files changed

+227
-167
lines changed

6 files changed

+227
-167
lines changed

docs/asciidoc/getting-started.adoc

Lines changed: 30 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,32 @@
11
== Getting Started
22

3-
Jooby comes with couple of options for getting started: manual, maven archetype and command line tool.
4-
5-
=== Java
6-
7-
1) Add the dependency:
8-
9-
[dependency, artifactId="jooby-netty"]
10-
.
11-
12-
[TIP]
13-
====
14-
Jooby is a multi-server web framework. You are free to choose between: Jetty, Netty and Undertow.
15-
====
16-
17-
2) Write code:
18-
19-
.App.java:
20-
[source, java]
21-
----
22-
import io.jooby.Jooby;
23-
24-
public class App extends Jooby {
25-
26-
{
27-
get("/", ctx -> "Hello World!");
28-
}
29-
30-
public static void main(String[] args) {
31-
runApp(args, App::new);
32-
}
33-
}
34-
----
35-
36-
=== Kotlin
37-
38-
1) Add Kotlin dependencies:
39-
40-
[dependency, artifactId="kotlin-stdlib-jdk8, kotlin-reflect:Optional. Only for MVC routes, kotlinx-coroutines-core:Optional. Only for suspend handlers"]
41-
.
42-
43-
2) Write code:
44-
45-
.App.kt
46-
[source, kotlin]
47-
----
48-
import io.jooby.runApp
49-
50-
fun main(args: Array<String>) {
51-
runApp(args) {
52-
53-
get("/") { ctx -> "Hello World!" }
54-
55-
}
56-
}
57-
----
58-
59-
Run `App`:
60-
61-
----
62-
INFO App started with:
63-
INFO PID: 21661
64-
INFO port: 8080
65-
INFO server: netty
66-
INFO routes:
67-
68-
GET /
69-
70-
listening on:
71-
http://localhost:8080/
72-
73-
----
74-
75-
Ready {love}!
76-
77-
=== Maven Archetype
78-
79-
The Maven archetype creates a minimal Jooby application.
80-
81-
.Interactive type
82-
[source, bash, subs="verbatim,attributes"]
83-
----
84-
mvn archetype:generate -B -DarchetypeArtifactId=jooby-archetype -DarchetypeGroupId=io.jooby -DarchetypeVersion={joobyVersion}
85-
----
86-
87-
You'll be ask for:
88-
89-
- `groupId`: used for application package name
90-
- `artifactId`: used for application name
91-
- `version`: application version
92-
93-
Alternative you can specify all these parameters inline:
94-
95-
.Inline
96-
[source, bash, subs="verbatim,attributes"]
97-
----
98-
mvn archetype:generate -B -DgroupId=mypackage -DartifactId=my-app -Dversion=1.0.0 -DarchetypeArtifactId=jooby-archetype -DarchetypeGroupId=io.jooby -DarchetypeVersion={joobyVersion}
99-
----
100-
101-
=== CLI
102-
103-
The command line tool provides a dynamic way of generating Jooby applications.
3+
The best way of getting started is using the `jooby console`. It is a small application that generates
4+
Jooby projects very quickly.
1045

1056
**Features**
1067

1078
- Maven or Gradle build
108-
- Java or Kotlin language
9+
- Java or Kotlin application
10910
- Script or MVC routes
110-
- Choose server: Jetty, Netty or Undertow
11+
- Jetty, Netty or Undertow application
11112
- Uber/Fat jar or https://github.com/fizzed/stork[Stork native launcher]
11213
- Dockerfile
11314
114-
**Install**
15+
To install the console:
11516

11617
- Download https://repo1.maven.org/maven2/io/jooby/jooby-cli/{joobyVersion}/jooby-cli-{joobyVersion}.zip[jooby-cli.zip]
11718
- Unzip `jooby-cli.zip` in your user home directory (or any other directory you prefer to)
11819
- Find the native launchers in the `bin` directory
11920
21+
[TIP]
22+
====
23+
You might want to add the native launcher `bin/jooby` or `bin/jooby.bat` to system path variable.
24+
So its globally accessible from any location.
25+
====
26+
12027
[NOTE]
12128
====
122-
To simplify documentation we use `jooby` as command. Windows users must use `jooby.bat`
29+
To simplify documentation we use `jooby` as command. Windows users must use `jooby.bat`
12330
====
12431

12532
.Setting workspace:
@@ -128,25 +35,15 @@ To simplify documentation we use `jooby` as command. Windows users must use `joo
12835
jooby set -w ~/Source
12936
----
13037

131-
All code will be placed inside the `~/Source` directory.
38+
All code will be saved inside the `~/Source` directory.
13239

133-
[TIP]
134-
====
135-
You might want to add the native launcher `bin/jooby` or `bin/jooby.bat` to system path variable.
136-
So its globally accessible from any location.
137-
====
40+
Workspace directory is ready!
41+
42+
Now type `jooby` hit ENTER.
13843

139-
Workspace directory is ready! Let's generate some code!! This time just run the `jooby` command.
14044
After prompt type `help create`:
14145

14246
.jooby
143-
[source, bash]
144-
----
145-
jooby> help create
146-
----
147-
148-
Output:
149-
15047
[source, bash]
15148
----
15249
jooby> help create
@@ -168,73 +65,70 @@ jooby>
16865

16966
The `create` command generates a Jooby application. Some examples:
17067

171-
.Creates `myapp` as Java Maven project:
68+
.Creates a Maven Java project:
17269
[source, bash]
17370
----
17471
jooby> create myapp
17572
----
17673

177-
.Creates `myapp` as Kotlin Maven project:
74+
.Creates a Maven Kotlin project:
17875
[source, bash]
17976
----
180-
jooby> create myapp -k
77+
jooby> create myapp --kotlin
18178
----
18279

183-
.Creates `myapp` as Java Gradle project:
80+
.Creates a Gradle Java project:
18481
[source, bash]
18582
----
186-
jooby> create myapp -g
83+
jooby> create myapp --gradle
18784
----
18885

189-
.Creates `myapp` as Kotlin Gradle project:
86+
.Creates a Gradle Kotlin project:
19087
[source, bash]
19188
----
192-
jooby> create myapp -gk
89+
jooby> create myapp --gradle --kotlin
19390
----
19491

19592
Maven and Java are the default options but you can easily override those with `-g -k` or `-gk` (order doesn't matter).
19693
Along with the build and language the `create` command adds two test classes: `UnitTest` and `IntegrationTest`.
19794

19895
Passing the `-m` or `--mvc` generates a MVC application:
19996

200-
.Creates `myapp` as MVC application:
97+
.Creates a Maven Java Mvc project:
20198
[source, bash]
20299
----
203-
jooby> create myapp -m
100+
jooby> create myapp --mvc
204101
----
205102

206103
The `--server` option, allow you to choose between: (J)etty, (N)etty or (U)ndertow:
207104

208-
.Creates `myapp` as MVC application:
105+
.Creates a Maven Java Project using Undertow:
209106
[source, bash]
210107
----
211108
jooby> create myapp --server undertow
212109
----
213110

214-
Maven/Gradle configuration generates an `uber/fat` jar at package time. Maven builds supports
111+
Maven/Gradle configuration generates an `uber/fat` jar at package time. Maven builds supports
215112
generation of https://github.com/fizzed/stork[Stork launchers].
216113

217-
.Creates `myapp` and generates stork launchers:
114+
.Creates a Maven Java Project with stork launchers:
218115
[source, bash]
219116
----
220117
jooby> create myapp --stork
221118
----
222119

223120
There is a `-d` or `--docker` option which generates a `Dockerfile`
224121

225-
.Creates `myapp` with docker:
122+
.Creates a docker file:
226123
[source, bash]
227124
----
228125
jooby> create myapp --docker
229126
----
230127

231128
The default package in all these examples is set to `app`, to get fully control of groupId, package, version, etc... Use the interactive mode:
232129

233-
.Fully customize `myapp`:
130+
.Interactive mode:
234131
[source, bash]
235132
----
236133
jooby> create myapp -i
237134
----
238-
239-
The jooby cli application is a small program that simplifies creation of project and provides options
240-
to fully customize your application.

docs/asciidoc/mvc-api.adoc

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ to define and execute routes.
55

66
The package `io.jooby.annotations` contains all the annotations available for MVC routes.
77

8-
Since 2.1.0, Jooby uses an annotation processing tool to convert MVC routes to script/lambda routes
9-
at compilation time. The tool reduces application startup time and eliminates the use of dynamic
10-
class loading.
11-
128
.MVC API:
139
[source,java,role="primary"]
1410
----
1511
import io.jooby.annotations.*;
1612
1713
@Path("/mvc") // <1>
18-
public class MyController {
14+
public class Controller {
1915
2016
@GET // <2>
2117
public String sayHi() {
@@ -26,7 +22,7 @@ public class MyController {
2622
public class App extends Jooby {
2723
2824
{
29-
mvc(new MyController()); // <3>
25+
mvc(new Controller()); // <3>
3026
}
3127
3228
public static void main(String[] args) {
@@ -42,33 +38,33 @@ public class App extends Jooby {
4238
import io.jooby.annotations.*;
4339
4440
@Path("/mvc") // <1>
45-
class MyController {
41+
class Controller {
4642
4743
@GET // <2>
4844
fun sayHi() : String {
4945
return "Hello Mvc!"
5046
}
5147
}
5248
53-
5449
fun main(args: Array<String>) {
5550
runApp(args) {
5651
mvc(MyController()) // <3>
5752
}
5853
}
59-
6054
----
6155

6256
<1> Set a path pattern. The `@Path` annotation is enable at class or method level
6357
<2> Add a HTTP method
6458
<3> Register/install the controller in the main application
6559

66-
The next section describes how to configure the annotation processing tool, but keep in mind all these
67-
can be done using the <<getting-started-cli, jooby console>>.
60+
=== Getting Started
61+
62+
To create a new MVC project open the `jooby` console and type:
6863

69-
=== APT
64+
jooby create myapp --mvc
7065

71-
==== Maven
66+
The <<getting-started, jooby console>> takes care of all configuration steps required by the
67+
annotation processing tool.
7268

7369
=== Parameters
7470

0 commit comments

Comments
 (0)