25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 19 ■ <strong>Spring</strong> Boot, Simplifying Everything<br />

The above command will jar up all the dependencies needed in one big jar. The jar will be created in the<br />

build/libs folder and it will be named according to the jar definition in the build.gradle (see Listing 19-1). Now<br />

you can run the <strong>Spring</strong> Boot application with<br />

java -jar ch19-spring-boot-0.1.0.jar<br />

and you should get the same output as shown in Figure 19-1 with the RESTful features.<br />

Creating a WAR File<br />

What happens if you need to create a WAR file because maybe you already have an application server like tcServer or<br />

Tomcat? You will need to make some small modifications. Let’s start first with the build.gradle file. You just need<br />

to add the war plug-in, replace the jar section for the war section, and add the configurations section. Listing 19-5<br />

shows the new build.gradle for creating a WAR file.<br />

Listing 19-5. build.gradle<br />

buildscript {<br />

repositories {<br />

jcenter()<br />

mavenCentral()<br />

maven {<br />

url "http://repo.spring.io/libs-snapshot"<br />

url 'http://repo.spring.io/milestone'<br />

url 'http://repo.spring.io/libs-release'<br />

}<br />

mavenLocal()<br />

}<br />

dependencies {<br />

classpath (group: 'org.springframework.boot', name:'spring-boot-gradle-plugin',<br />

version: '1.1.1.RELEASE')<br />

}<br />

}<br />

apply plugin: 'java'<br />

apply plugin: 'eclipse'<br />

apply plugin: 'idea'<br />

apply plugin: 'war'<br />

apply plugin: 'spring-boot'<br />

war {<br />

}<br />

baseName = 'ch19-spring-boot'<br />

version = '0.1.0'<br />

repositories {<br />

mavenCentral()<br />

maven {<br />

url "http://repo.spring.io/libs-snapshot"<br />

url 'http://repo.spring.io/milestone'<br />

url 'http://repo.spring.io/libs-release'<br />

}<br />

}<br />

270

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!