June 4, 2015

Spring with Maven using Spring Boot

I started playing around Spring after a long time. I needed to quickly get ramped up and hence used Spring Boot module to get spring,maven, embedded tomcat up and running. The sample files in this example I have committed to my public github repository here – https://github.com/ashikuzzaman/springchecks

10. Run the command “mvn spring-boot:run” to compile the program, download tomcat and other dependent jar files and bring tomcat up and running with the webapp created that uses your java file to show output in the browser.

14. To create an executable jar first we need to add a maven plugin for spring boot. Add the below elements under dependenceies scetion in pom.xml – <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>

15. Add an etnry if you want to change the JDK major version that you want to use. For example, if you want to specify that you want to use Java 7, here is an entry you can add just after the previous build element that you added –

<properties> <java.version>1.7</java.version> </properties>

16. Save pom.xml and run “mvn package”

17. If you look in maven’s target directory you should see myproject-0.0.1-SNAPSHOT.jar file. You can print verbose what’s in it by “jar tvf target/myproject-0.0.1-SNAPSHOT.jar”

18. To run the application from command line, use the following command “java -jar target/myproject-0.0.1-SNAPSHOT.jar”