|
|
@@ -71,7 +71,9 @@ In a project directory of your choosing, create the following subdirectory struc
|
|
71
|
71
|
└── java
|
|
72
|
72
|
└── hello
|
|
73
|
73
|
|
|
|
74
|
+
|
|
74
|
75
|
### Create a Gradle build file
|
|
|
76
|
+Below is the [initial Gradle build file](https://github.com/springframework-meta/gs-rest-service/blob/master/initial/build.gradle). But you can also use Maven. The pom.xml file is included [right here](https://github.com/springframework-meta/gs-rest-service/blob/master/initial/pom.xml).
|
|
75
|
77
|
|
|
76
|
78
|
`build.gradle`
|
|
77
|
79
|
```gradle
|
|
|
@@ -106,6 +108,8 @@ task wrapper(type: Wrapper) {
|
|
106
|
108
|
gradleVersion = '1.7'
|
|
107
|
109
|
}
|
|
108
|
110
|
```
|
|
|
111
|
+
|
|
|
112
|
+
|
|
109
|
113
|
|
|
110
|
114
|
This guide is using [Spring Boot's starter POMs](/guides/gs/spring-boot/).
|
|
111
|
115
|
|
|
|
@@ -242,6 +246,8 @@ The [`@EnableAutoConfiguration`][] annotation switches on reasonable default beh
|
|
242
|
246
|
|
|
243
|
247
|
Now that your `Application` class is ready, you simply instruct the build system to create a single, executable jar containing everything. This makes it easy to ship, version, and deploy the service as an application throughout the development lifecycle, across different environments, and so forth.
|
|
244
|
248
|
|
|
|
249
|
+Below are the Gradle steps, but if you are using Maven, you can find the updated pom.xml [right here](https://github.com/springframework-meta/gs-rest-service/blob/master/complete/pom.xml) and build it by typing `mvn clean package`.
|
|
|
250
|
+
|
|
245
|
251
|
Update your Gradle `build.gradle` file's `buildscript` section, so that it looks like this:
|
|
246
|
252
|
|
|
247
|
253
|
```groovy
|
|
|
@@ -261,6 +267,7 @@ Further down inside `build.gradle`, add the following to the list of applied plu
|
|
261
|
267
|
```groovy
|
|
262
|
268
|
apply plugin: 'spring-boot'
|
|
263
|
269
|
```
|
|
|
270
|
+You can see the final version of `build.gradle` [right here]((https://github.com/springframework-meta/gs-rest-service/blob/master/complete/build.gradle).
|
|
264
|
271
|
|
|
265
|
272
|
The [Spring Boot gradle plugin][spring-boot-gradle-plugin] collects all the jars on the classpath and builds a single "über-jar", which makes it more convenient to execute and transport your service.
|
|
266
|
273
|
It also searches for the `public static void main()` method to flag as a runnable class.
|
|
|
@@ -271,24 +278,32 @@ Now run the following command to produce a single executable JAR file containing
|
|
271
|
278
|
$ ./gradlew build
|
|
272
|
279
|
```
|
|
273
|
280
|
|
|
274
|
|
-Now you can run the JAR by typing:
|
|
|
281
|
+If you are using Gradle, you can run the JAR by typing:
|
|
275
|
282
|
|
|
276
|
283
|
```sh
|
|
277
|
284
|
$ java -jar build/libs/gs-rest-service-0.1.0.jar
|
|
278
|
285
|
```
|
|
279
|
286
|
|
|
|
287
|
+If you are using Maven, you can run the JAR by typing:
|
|
|
288
|
+
|
|
|
289
|
+```sh
|
|
|
290
|
+$ java -jar target/gs-rest-service-0.1.0.jar
|
|
|
291
|
+```
|
|
|
292
|
+
|
|
280
|
293
|
[spring-boot-gradle-plugin]: https://github.com/SpringSource/spring-boot/tree/master/spring-boot-tools/spring-boot-gradle-plugin
|
|
281
|
294
|
|
|
282
|
295
|
> **Note:** The procedure above will create a runnable JAR. You can also opt to [build a classic WAR file](/guides/gs/convert-jar-to-war/) instead.
|
|
283
|
296
|
|
|
284
|
297
|
Run the service
|
|
285
|
298
|
-------------------
|
|
286
|
|
-Run your service at the command line:
|
|
|
299
|
+If you are using Gradle, you can run your service at the command line this way:
|
|
287
|
300
|
|
|
288
|
301
|
```sh
|
|
289
|
302
|
$ ./gradlew clean build && java -jar build/libs/gs-rest-service-0.1.0.jar
|
|
290
|
303
|
```
|
|
291
|
304
|
|
|
|
305
|
+> **Note:** If you are using Maven, you can run your service by typing `mvn clean package && java -jar target/gs-rest-service-0.1.0.jar`.
|
|
|
306
|
+
|
|
292
|
307
|
|
|
293
|
308
|
Logging output is displayed. The service should be up and running within a few seconds.
|
|
294
|
309
|
|