官术网_书友最值得收藏!

Creating a deployable

We are not going to run our service on Eclipse. We would like to deploy it on a server. There are two options for doing this:

  • Create a WAR and deploy it in Tomcat or any other web container. This is the traditional method.
  • Create a JAR with the runtime (Tomcat) included so that you just need Java to execute the service.

In cloud application development, the second option, also called fat JAR or uber JAR, is becoming popular for the following reasons:

  • The deployable is self-contained with all the dependencies it needs. This reduces the chances of environment mismatch as the deployable unit is deployed to Dev, Test, UAT, and Production. If it works in development, there is a good chance it will work across all the other environments.
  • The host, server, or container where the service is deployed need not have a preinstalled application server or servlet engine. Just a basic JRE is good enough.

Let's look at the steps to create a JAR file and run it.

Include the following dependencies of the POM file:

<build><plugins><plugin> 
            <groupId>org.springframework.boot</groupId> 
            <artifactId>spring-boot-maven-plugin</artifactId> 
</plugin></plugins></build> 

Now, run it by right-clicking the project in the explorer and choosing Run As | Maven Install.

You will see product-0.0.1-SNAPSHOT.jar in the target directory of the project folder structure.

Navigate to the product folder so that you see the target directory in the command line and then run the JAR through a Java command, as shown in the following screenshot:

You will see Tomcat listening to the port at the end of the startup. Test it through the browser again. Milestone achieved.

主站蜘蛛池模板: 镇坪县| 荔浦县| 衡水市| 巩留县| 石柱| 贡山| 霞浦县| 胶南市| 中牟县| 紫金县| 淅川县| 临沂市| 搜索| 建平县| 卢龙县| 资兴市| 湖北省| 乐平市| 江阴市| 冀州市| 齐齐哈尔市| 汾阳市| 张家界市| 大丰市| 广州市| 徐汇区| 尼勒克县| 泾阳县| 星座| 惠州市| 湟中县| 永清县| 江源县| 沁阳市| 佛学| 蚌埠市| 健康| 阳西县| 绥芬河市| 安庆市| 乌审旗|