-
Notifications
You must be signed in to change notification settings - Fork 3k
Various documentation fixes #666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
f61e983
91ac664
b808c82
00036ba
ead2453
6bb3aa8
cebb3b6
9be53bc
47ec614
fc19f4b
58c2279
29882ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,17 @@ Remember, you need to configure Maven as indicated in the link:maven-config.html | |
We recommend you to follow the instructions in the next sections and create the application step by step. | ||
However, you can go right to the completed example. | ||
|
||
Clone the Git repository: `git clone https://github.com/protean-project/quickstarts.git`, or download an https://github.com/protean-project/quickstarts/archive/master.zip[archive]. | ||
Clone the Git repository: `git clone https://github.com/jbossas/protean-quickstarts.git`, or download an https://github.com/jbossas/protean-quickstarts/archive/master.zip[archive]. | ||
|
||
The solution is located in the `application-configuration` directory. | ||
|
||
== Creating the Maven project | ||
|
||
First, we need a new project. Create a new project with the following command: | ||
|
||
[source] | ||
[source, subs=attributes+] | ||
---- | ||
mvn org.jboss.shamrock:shamrock-maven-plugin:1.0.0.Alpha1-SNAPSHOT:create \ | ||
mvn org.jboss.shamrock:shamrock-maven-plugin:{shamrock-version}:create \ | ||
-DprojectGroupId=org.acme \ | ||
-DprojectArtifactId=application-configuration \ | ||
-DclassName="org.acme.config.GreetingResource" \ | ||
|
@@ -39,6 +39,9 @@ mvn org.jboss.shamrock:shamrock-maven-plugin:1.0.0.Alpha1-SNAPSHOT:create \ | |
It generates: | ||
|
||
* the Maven structure | ||
* a landing page accessible on `http://localhost:8080` | ||
* an example of `Dockerfile` | ||
* the application configuration file | ||
* an `org.acme.config.GreetingResource` resource | ||
* an associated test | ||
|
||
|
@@ -91,7 +94,7 @@ public String hello() { | |
|
||
We need to create the file providing the values. | ||
By default, Shamrock reads `META-INF/microprofile-config.properties`. | ||
Create the `src/main/resources/META-INF/microprofile-config.properties` with the following content: | ||
Edit the `src/main/resources/META-INF/microprofile-config.properties` with the following content: | ||
|
||
[source] | ||
---- | ||
|
@@ -100,6 +103,17 @@ greeting.message = hello | |
greeting.name = shamrock | ||
---- | ||
|
||
Once set, check the application with: | ||
|
||
[source] | ||
---- | ||
$ curl http://localhost:8080/greeting | ||
hello shamrock! | ||
---- | ||
|
||
TIP: If the application requires configuration values and these values are not set, an error is thrown. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A TIP admonition would make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's already an admonition (single line admonition). Admonition blocks are supported too and allows adding title and paragraph as content. However, for short notes like this one I've found single-line more readable. |
||
So you can quickly now when your configuration is complete. | ||
cescoffier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
== Update the test | ||
|
||
We also need to update the functional test to reflect the changes made to endpoint. | ||
|
@@ -140,4 +154,4 @@ Changing the configuration file is immediately reflected. | |
You can add the `greeting.suffix`, remove the other properties, change the values, etc. | ||
|
||
As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file. | ||
You can also generate the native executable. | ||
You can also generate the native executable with `mvn clean package -Pnative` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this patch but maybe we should be consistent with what we do in Shamrock proper and use Not sure it's worth the work though. In any case, if we decide to do it, let's do it in a follow-up PR (and update all the guides). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to prefer specifying profiles explicitly, at least for the users. Now, if the user is a Maven user, he can definitely change that. But we can change the behavior (it would require changing the template, doc, and quickstarts). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ Remember, you need to configure Maven as indicated in the link:maven-config.html | |
We recommend you to follow the instructions in the next sections and create the application step by step. | ||
However, you can go right to the completed example. | ||
|
||
Clone the Git repository: `git clone https://github.com/protean-project/quickstarts.git`, or download an https://github.com/protean-project/quickstarts/archive/master.zip[archive]. | ||
Clone the Git repository: `git clone https://github.com/jbossas/protean-quickstarts.git`, or download an https://github.com/jbossas/protean-quickstarts/archive/master.zip[archive]. | ||
|
||
The solution is located in the `application-lifecycle-events` directory. | ||
|
||
|
@@ -42,6 +42,9 @@ mvn org.jboss.shamrock:shamrock-maven-plugin:{shamrock-version}:create \ | |
It generates: | ||
|
||
* the Maven structure | ||
* a landing page accessible on `http://localhost:8080` | ||
* an example of `Dockerfile` | ||
* the application configuration file | ||
* an `org.acme.events.GreetingResource` resource | ||
* an associated test | ||
|
||
|
@@ -80,20 +83,14 @@ public class AppLifecycleBean { | |
1. Method called when the application is starting | ||
2. Method called when the application is terminating | ||
|
||
[INFO] | ||
==== | ||
The events are also called in _dev mode_ between each redeployment. | ||
==== | ||
TIP: The events are also called in _dev mode_ between each redeployment. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, one line admonitions are supported this way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
[INFO] | ||
==== | ||
The methods can access injected beans. Check the https://github.com/protean-project/quickstarts/blob/master/application-lifecycle-events/src/main/java/org/acme/events/AppLifecycleBean.java[AppLifecycleBean.java] class for details. | ||
==== | ||
NOTE: The methods can access injected beans. Check the https://github.com/jbossas/protean-quickstarts/blob/master/application-lifecycle-events/src/main/java/org/acme/events/AppLifecycleBean.java[AppLifecycleBean.java] class for details. | ||
|
||
== Package and run the application | ||
|
||
Run the application with: `mvn compile shamrock:dev`, the logged message is printed. | ||
When the application is stopped, the second log message is printed. | ||
|
||
As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file. | ||
You can also generate the native executable. | ||
You can also generate the native executable using `mvn clean package -Pnative`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,33 +49,34 @@ Clone the Git repository: `git clone [email protected]:jbossas/protean-quickstarts. | |
|
||
The solution is located in the `getting-started` directory. | ||
|
||
== Creating the pom file | ||
== Bootstrapping the project | ||
|
||
In your favorite IDE, create a new Maven project. | ||
It should generate a `pom.xml` file with a content similar to: | ||
The easiest way to create a new Protean project is to open a terminal and run the following command: | ||
|
||
|
||
[source,xml] | ||
[source, subs=attributes+] | ||
---- | ||
mvn org.jboss.shamrock:shamrock-maven-plugin:{shamrock-version}:create \ | ||
-DprojectGroupId=org.acme \ | ||
-DprojectArtifactId=getting-started \ | ||
-DclassName="org.acme.quickstart.GreetingResource" \ | ||
-Dpath="/hello" | ||
---- | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.acme</groupId> | ||
<artifactId>shamrock-quickstart</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
It generates: | ||
|
||
</project> | ||
---- | ||
* the Maven structure | ||
* an `org.acme.quickstart.GreetingResource` resource exposed on `/hello` | ||
* an associated unit test | ||
* a landing page accessible on `http://localhost:8080` | ||
* an example of `Dockerfile` | ||
* the application configuration file | ||
|
||
Add the Shamrock Maven plugin to the `pom.xml` file: | ||
Once generated, look at the `pom.xml`. | ||
You will find the import of the Shamrock BOM, allowing to omit the version on the different Protean dependencies. | ||
cescoffier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
In addition, you can see the `shamrock-maven-plugin` responsible of the packaging of the application and also providing the development mode. | ||
|
||
[source,xml,subs=attributes+] | ||
---- | ||
<properties> | ||
<shamrock.version>{shamrock-version}</shamrock.version> | ||
<surefire.version>{surefire-version}</surefire.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
|
@@ -112,11 +113,10 @@ Add the Shamrock Maven plugin to the `pom.xml` file: | |
Shamrock can be seen as {project-name} core. | ||
==== | ||
|
||
As we are going to create a JAX-RS endpoint, you also need to add the following dependencies: | ||
If we focus on the dependencies section, you can see 2 extensions allowing the development of REST applications: | ||
|
||
[source,xml] | ||
---- | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-jaxrs-deployment</artifactId> | ||
|
@@ -125,7 +125,6 @@ As we are going to create a JAX-RS endpoint, you also need to add the following | |
<groupId>org.jboss.shamrock</groupId> | ||
<artifactId>shamrock-arc-deployment</artifactId> | ||
</dependency> | ||
</dependencies> | ||
---- | ||
|
||
[NOTE] | ||
|
@@ -134,9 +133,9 @@ As we are going to create a JAX-RS endpoint, you also need to add the following | |
ArC is a CDI-based dependency injection solution - see also link:cdi-reference.html[Contexts and Dependency Injection]. | ||
==== | ||
|
||
=== Creating the JAX-RS resource | ||
=== The JAX-RS resources | ||
|
||
Create the `src/main/java/org/acme/quickstart/GreetingResource.java` file with the following content: | ||
During the project creation, the `src/main/java/org/acme/quickstart/GreetingResource.java` file as been created with the following content: | ||
cescoffier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[source,java] | ||
---- | ||
|
@@ -158,6 +157,8 @@ public class GreetingResource { | |
} | ||
---- | ||
|
||
It's a very simple REST endpoint, returning "hello" to request on "/hello". | ||
cescoffier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[TIP] | ||
.Differences with vanilla Jax-RS | ||
==== | ||
|
@@ -201,11 +202,11 @@ $ curl http://localhost:8080/hello | |
hello | ||
``` | ||
|
||
Hit `CTRL+C` to stop the application. | ||
Hit `CTRL+C` to stop the application, but you can also keep it running and enjoy the blasting fast hot-reload. | ||
|
||
== Using injection | ||
|
||
Let's add a companion bean. | ||
Let's modify the application and add a companion bean. | ||
Create the `src/main/java/org/acme/quickstart/GreetingService.java` file with the following content: | ||
|
||
[source, java] | ||
|
@@ -258,15 +259,14 @@ public class GreetingResource { | |
} | ||
---- | ||
|
||
Start the application and check that http://localhost:8080/hello/greeting/shamrock returns `hello shamrock`. | ||
|
||
|
||
If you stopped the application, restart the application with `mvn compile shamrock:dev`. | ||
Then check that http://localhost:8080/hello/greeting/shamrock returns `hello shamrock`. | ||
|
||
== Testing | ||
|
||
All right, so far so good, but wouldn't it be better with a few tests, just in case. | ||
|
||
Edit the `pom.xml` file to add the 2 following dependencies: | ||
In the generated `pom.xml` file, you can see 2 test dependencies: | ||
|
||
[source,xml,subs=attributes+] | ||
---- | ||
|
@@ -285,17 +285,18 @@ Edit the `pom.xml` file to add the 2 following dependencies: | |
---- | ||
|
||
Note that Shamrock uses JUnit 5 by default, which means that you may need to upgrade the version of surefire | ||
that is in use. Do this by adding the following to the `<build><plugins>` section of `pom.xml`: | ||
that is in use. This is done in `<build><plugins>` section of `pom.xml`: | ||
cescoffier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[source,xml,subs=attributes+] | ||
---- | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>{surefire-version}</version> | ||
<version>${surefire.version}</version> | ||
</plugin> | ||
---- | ||
|
||
Then, create the `src/test/java/org/acme/quickstart/GreetingResourceTest.java` with the following content: | ||
The project generation contains a simple test. | ||
Edit the `src/test/java/org/acme/quickstart/GreetingResourceTest.java` to match the following content: | ||
|
||
[source,java] | ||
---- | ||
|
@@ -348,8 +349,9 @@ It produces 2 jar files: | |
|
||
* `shamrock-quickstart-1.0-SNAPSHOT.jar` - containing just the classes and resources of the projects, it's the regular | ||
artifact produced by the Maven build; | ||
* `shamrock-quickstart-1.0-SNAPSHOT-runner.jar` - being an executable _über-jar_. | ||
It embeds all the dependencies required to run the application. | ||
* `shamrock-quickstart-1.0-SNAPSHOT-runner.jar` - being an executable _jar_. Be aware that it's not an _über-jar_ as | ||
the dependencies are copied into the `target/lib` directory. Refer to the Maven plugin documentation to generate an | ||
cescoffier marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
_über-jar_ embedding the dependencies. | ||
|
||
You can run the application using: `java -jar target/shamrock-quickstart-1.0-SNAPSHOT-runner.jar` | ||
cescoffier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -368,7 +370,7 @@ public CompletionStage<String> hello() { | |
} | ||
---- | ||
|
||
The async version of the code is available in the https://github.com/protean-project/quickstarts[Github] repository, in the `getting-started-async` directory. | ||
The async version of the code is available in the https://github.com/jbossas/protean-quickstarts[Github] repository, in the `getting-started-async` directory. | ||
|
||
== What's next? | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.