Java Notes---Deploying Javaweb projects to cloud servers

Source: Internet
Author: User

First, preface

We've already tasted the sweetness of deploying code on cloud servers, and now the main course is on the way to deploy our Javaweb project to a cloud server. Excited, huh? Calm and calm ~

II. Deployment of the project

We are already aware of the deployment of the Java Web project on the local machine (whether Windows or Linux), what about deploying a Java Web project on a cloud server? in fact, it is very simple, or can not be separated from the WEB project deployment of the three points:
①-based JDK environment
② a WEB server. such as Tomcat, JBoss
③ a database. such as: MySQL

The deployment of Java WEB projects on cloud servers is the same as when deployed in Windows and Linux. At most, you can only use the Pure command mode to operate, in fact the process is the same.

2.1 Environment Preparation

Since it is a Java Web project deployment, first of all naturally need to configure the relevant environment Luo. That is: first build the Java development environment on the cloud host, such as OpenJDK installation, TOMCAT installation, Mysql database installation.
Note: The installation of these software is no longer described in this article, I will be in another 2 articles elaborated in detail.

  • OpenJDK and Tomcat installation, read: Java notes-cenos Configuring the Java Development environment (OpenJDK + Tomcat8)
  • MySQL installation, please read: Java Note-cenos configuration MySQL
2.2 Project Deployment

To deploy the Java Web project, at least upload the project to the cloud server. In fact, the process is very simple, basically is the following three steps :
① Package Upload: Package The project into a war file and then use FileZilla to upload to the remote server
② deployment: Use the CP or MV command to move the war file to WebApps under the Tomcat directory
③ reboot Tomcat to visit our project

In this process, we need to be aware of. As a general rule, as a Web project, we certainly have database usage. So what about the database section? In fact, simply dump our existing database into a SQL file and then upload the SQL file to the cloud server to execute. In MySQL, for example, the following actions:

Mysql case

Dump as SQL script and upload : The database used by our project is converted to SQL file locally and uploaded to the cloud server

Execute SQL: Then execute the SQL file into MySQL

There is a mistake in discovering execution. The reason is that we do not thinkphp this database in MySQL at this time. We look under the current database, execute the command show databases;

Found that there really is no thinkphp this database, so we create a, execute command create database thinkphp;

Execute again

Found or an error. The reason is that we are currently using the MySQL database instead of the thinkphp database. So we switch to the thinkphp database, execute the command use thinkphp, and then execute the SQL file again:

View Results

First of all, regardless of the display is garbled (because the SQL file you have just looked at this will be the result), you can see that it has been done
Deployment Project : Deploy the project to a Tomcat container, or use the CP or MV command to move the war file to/usr/local/tomcat8/webapps/, restart Tomcat, and then access

You can see the success, right? It's not, because we've found that the part of the database that needs to get the data has no data, so why? There are several possible reasons for the error:
The mysql5.1.10 drive jar is used in the ① project, and the cloud server defaults to using mysql5.1.73 so either reload a MySQL or change the driver in the project to mysql5.1.73.
② the MySQL driver jar is not put into jvm/java-1.8.0xxx/jre/lib/ext/
③ Password is incorrect
④ is using the root account, and the root account does not require a password to access MySQL under Linux

Through the troubleshooting, found that because the project is using the root account, so we in the local project code about the database connection part of the change, the password is empty string, re-deployment, you can return to normal, see the results!

Successful display, connected to the mysql!

Java Notes---Deploying Javaweb projects to cloud servers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.