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

Deploying to Tomcat

Before we proceed with View and Controller for handling views, we will deploy the app developed so far to Tomcat. You can download Tomcat 8.5 from here (https://tomcat.apache.org/download-80.cgi). Installation is as simple as extracting the ZIP/TAR file onto your file system.

Let's create a user admin and manager-gui role in Tomcat. To do this, have to edit apache-tomcat-8.5.23/conf/tomcat-users.xml and add the following line:

<role rolename="manager-gui" />
<user username="admin" password="admin" roles="manager-gui" />

Starting up Tomcat is simple, as follows: 

  1. Navigate to apache-tomcat-8.5.23/bin
  2. Run startup.bat

Navigate to http://localhost:8080/manager/html and enter admin, and admin for username and password respectively, to be able to view Tomcat's manager console. The initial part of the page will list the applications deployed in the current instance, and toward the later part of the page you will find an option to upload a WAR file to deploy the application, as shown in the following screenshot:

We can either upload the WAR file generated after running mvn package or update the server.xml of the Tomcat instance to refer to the target directory of the project to be able to deploy automatically. The latter approach can be used for development, while the former that is WAR deployment can be used for production.

In a production system, you can have a continuous deployment server generate a WAR file and deploy to a remote Tomcat instance. In this scenario, we will use the latter approach of updating the Tomcat's configuration. You have to add the following line of code in the Tomcat's server.xml file, located at TOMCAT_HOME/conf/server.xml:

<Context path="/world" docBase="<<Directory path where you keep WAR file>>" 
reloadable="true" />

The preceding line has to be added between the <Host></Host> tags. Alternatively, you can configure Tomcat in your IDE (for example, Eclipse), which is more convenient for development purposes. We will build the project with Maven, but before that, please add following configuration to the <properties></properties> section of pom.xml:

<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>

This will make sure to choose the correct Java compiler version while building (packaging) the application with Maven from the command line. Next is to build the project using the mvn package and run Tomcat using TOMCAT_HOME/bin/startup.bat, and once the server is UP, you can visit the API http://localhost:8080/worldgdp/api/countries in the browser to see the following input:

主站蜘蛛池模板: 满洲里市| 武隆县| 乐昌市| 卢湾区| 扎鲁特旗| 盐边县| 丁青县| 霍州市| 肇源县| 镇康县| 四川省| 班玛县| 津南区| 孝义市| 保德县| 乌拉特前旗| 永州市| 福贡县| 夏河县| 合江县| 韶关市| 政和县| 台安县| 偏关县| 陈巴尔虎旗| 晋中市| 中卫市| 石城县| 安平县| 富源县| 满洲里市| 波密县| 信阳市| 叶城县| 阿拉善左旗| 盐津县| 武邑县| 胶州市| 页游| 全州县| 满洲里市|