Home > Java > javaTutorial > body text

How to install tomcat and deploy Java web projects on CentOS

WBOY
Release: 2023-04-29 23:01:05
forward
1747 people have browsed it

1. Preparation

a. Download the tomcat linux package, address:, the version we downloaded is 8.0, the download method is as shown in the figure: CentOS如何安装tomcat并部署Java Web项目

b. Because the installation of tomcat depends on java jdk, we need to determine whether jdk is installed under the linux system

b.1 Use (xshell) to connect to the linux system

b.2 Enter the command: java -version. If the jdk version number is displayed, it proves that it has been installed. If it is not displayed, it proves that it is not installed. If it is not installed, please refer to the following address to install it: //www .jb51.net/os/redhat/73016.html, as shown in the figure: CentOS如何安装tomcat并部署Java Web项目

c. The software and systems required for operation are as follows: virtual machine (vmware), installed in the virtual machine centos system, xshell, xftp, tomcat8.0, webdemo developed by myeclipse, apache-tomcat-8.0.29.tar.gz.

2. Install tomcat8.0 under linux

a. After the above preparations, we now have an environment that can be installed and released. If not, Please inquire and install yourself.

b. Then use the command in xshell to jump to the creator’s own folder under local: kencery

b.1 cd usr/local/ mkdir kencery cd kencery/

c. Then use xftp to copy tomcat to the kencery folder, as shown in the figure: CentOS如何安装tomcat并部署Java Web项目

d. Unzip the uploaded tomcat8.0 and unzip it Then rename it to tomcat, as shown in the figure:

d.1 tar -zxv -f apache-tomcat-8.0.29.tar.gz

d. 2 mv apache-tomcat-8.0.29 tomcat

d.3 cd tomcatCentOS如何安装tomcat并部署Java Web项目

e. After the analysis is completed, you can start tomcat and check whether the installation is successful. , the command is as follows, as shown in the figure:
  /usr/local/kencery/tomcat/bin/startup.shCentOS如何安装tomcat并部署Java Web项目
    

The information as shown in the figure appears, It means the startup is successful. At this time, we can access it under Windows. If the tomcat homepage can be displayed, it means that no operation is required. If it cannot be displayed, port 8080 of the firewall needs to be opened in Linux.

f. To open port 8080 in the firewall under Linux, use the following command:

f.1 vim /etc/sysconfig/iptables

f.2 After opening, press the keyboard (i) to enter the editing mode and write to the development port 8080, as shown in the figure: CentOS如何安装tomcat并部署Java Web项目          

f.3 After writing, we press the keyboard ( esc) button to exit, then press (:wq) to save and close vim.

g. Then restart the firewall, the command is as follows:

service iptables restart
Copy after login

h. Then enter it in the browser again. If you see the tomcat system interface, it means the installation is successful. You can proceed as follows One step away.

i. The command to stop tomcat is: /usr/local/tomcat/bin/shutdown.sh

3. Set up tomcat server startup in linux and close

a. As shown in 2, we have completed the installation of tomcat and can deploy the project after parsing it. However, there is a problem here, that is, the Linux system and restarting us every time All need to connect the path and execute the command, then we can set up the horizontal service form to achieve this function.

b. Execute the command: vim /etc/rc.d/init.d/tomcat, create a script file, write the following code in the file, save and exit
linux

c. Add permissions to the file so that the script file can be executed. The command is chmod 755 /etc/rc.d/init.d/tomcat

d. Add it to the service. The command is chkconfig --add /etc/rc.d/init.d/tomcat

e. Then add the following configuration file to the end of the catalina.sh file in tomcat, the command It is:

vim /usr/local/kencery/tomcat/bin/catalina.sh
    export java_home=/usr/local/kencery/javajdk  #javajdk的安装路径,使用echo $java_home命令可以读取
    export catalina_home=/usr/local/kencery/tomcat
    export catalina_base=/usr/local/kencery/tomcat
    export catalina_tmpdir=/usr/local/kencery/tomcat/temp
Copy after login

f. If all the above work goes smoothly and an error is reported, the configuration is complete. You can enter the commands service tomcat start and service tomcat stop to verify (please experiment by yourself).

4. Set up tomcat startup in linux

a. Through the settings in the third step, we can easily set up and shut down tomcat. But there is a problem here, that is, when the server is shut down and restarted, the service cannot start by itself when the computer starts. Then we can set the tomcat service to start at boot.

b. Open the file that opens the linux settings and write the following configuration file to the end of the file. The command is:

vim /etc/rc.d/rc.local
    export java_home=/usr/local/kencery/javajdk
    export classpath=.:$java_home/jre/lib/rt.jar:$java_home/lib/dt.jar:$java_home/lib/tools.jar
    export path=$path:$java_home/bin
    export catalina_home=/usr/local/kencery/tomcat/
    #tomcat自启动
    /usr/local/kencery/tomcat/bin/startup.
Copy after login

c.tomcat depends on java's jdk. So when setting up, jdk is also imported synchronously.

d.完成上面的步骤之后我们就可以将centos关机重启检查一番。

5.给tomcat设置用户名和密码登录

a.当tomcat安装完成之后,访问即可以看到tomcat发布的网站,这时候需要管理我们发布网站,就需要登录tomcat,那么在centos中如何设置登录名和密码。

b.在tomcat安装包下面的conf文件下含有一个tomcat-user.xml文件,修改此文件即可,命令为:vim tomcat-users.xml

c.在打开的xml配置文件最后面写入下面这段配置文件之后保存并且退出即可。

    <role rolename="admin-gui"/>  
    <role rolename="manager-gui"/>
    <user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
Copy after login

d.在这里会出现一个问题,因为tomcat-users.xml里面有注释的用户设置的信息,取消注释,用文件提供的用户名和密码去访问的时候,会出现403错误,什么原因呢?这是因为我们没有指定用户所拥有的权限的原因,如我们现在想访问tomcat中图形化管理应用的功能,也就是manager app,就需要指定manager-gui的权限,如果想访问host manager就必须指定admin-gui权限,故而如c所示的配置。

e.配置完用户名密码之后,需要重新启动tomcat,命令如下:
   

 service tomcat stop
       service tomcat start
Copy after login

f. 重启服务之后,检测是否登录成功,如果登录进入系统,则说明登录成功。

6.使用myeclipse打包java web项目

a.以上所有工作完成之后,我们需要一个简单的项目来打包发布,那么在myeclipse中如何打包项目呢

b.随便创建一个javaweb项目,如图所示:
CentOS如何安装tomcat并部署Java Web项目

c.在项目上单击右键选择export-选择javaee文件夹-选择war file(myeclipse),单击next>如图所示,选择存放打包程序的地址,单击finish完成,即实现了打包,在完成之后可以去你打包的地方看一下是否打包成功。

CentOS如何安装tomcat并部署Java Web项目
d.myeclipse10.7打包程序的时候当选择war file(myeclipse),单击next>的时候ide奔溃的解决办法。   

d.1 此错误可能是在破解的时候没有破解的很干净,所以需要执行下面步骤   

d.2 下载文件com.genuitec.eclipse.export.wizard_9.0.0.me201211011550.jar,下载地址为

d.3 找到myeclipse安装环境的地址,我的安装坏境是:d:\program files\myeclipse\common\plugins,将下载下来的文件解析之后替换到plugins中的同名文件(替换后,最好将jar文件改成.txt文件结尾,然后重启myeclipse10,然后关闭,再将jar改回.jar为扩展名的状态,重启后即可)。

d.4 已测试,没任何问题,完美实现,如果大家遇到,则按照这种思路解决即可。

7.将java web项目发布到tomcat8.0下面并且访问展示

a.以上所有工作都完成之后,我们就可以将打包的javaweb程序发布到tomcat下即可。

b.tomcat默认的发布web项目的目录是:webapps

c.将导出的war包直接使用xftp上传到webapps根目录下,随着tomcat的启动,war包可以自动被解析。

d.然后调用路径查询是否安装成功,如图所示:则表示安装成功CentOS如何安装tomcat并部署Java Web项目

The above is the detailed content of How to install tomcat and deploy Java web projects on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!