如何在tomcat服务器中手动部署war包
引言
- 什么是tomcat?
- The Apache Tomcat® software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket specifications are developed under the Java Community Process.
- 以上是官网对tomcat的一个简要介绍,tomcat是apache公司的一款开源服务器,是目前最为流行的web服务器之一,下文开始简要阐述tomcat的下载及安装
tomcat的下载
上tomcat官网
点击已经完成的版本achieves
进入后下载对应的版本,为了保守起见,我选择的是tomcat7的linux安装包,直接点解下载即可。
tomcat离线安装
解压tomcat
准备tomcatliunux安装包,解压
tar -zxvf apache-tomcat-7.0.57.tar.gz -C ./apache-tomcat-7.0.57_4
tomcat运行需要依赖jdk,所以需要查看jdk运行环境,没有安装jdk的童鞋请查看jdk离线安装,安装好jdk后开始配置tomcat的环境变量。进入tomcat解压文件下
cd /home/sy/websitedeployment/apache-tomcat-7.0.57_4/apache-tomcat-7.0.57/bin
tomcat环境变量的配置
修改环境变量执行
vim ./startup.sh
输入以下命令并保存
export JDK8=/usr/develop/java/jdk1.8.0_191
export JAVA_HOME=${JDK8}
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export TOMCAT_HOME_4=/home/sy/websitedeployment/apache-tomcat-7.0.57_4
对shutdown.sh同样需要执行这个命令,执行
vim ./shutdown.sh
输入以下命令并保存
export JDK8=/usr/develop/java/jdk1.8.0_191
export JAVA_HOME=${JDK8}
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export TOMCAT_HOME_4=/home/sy/websitedeployment/apache-tomcat-7.0.57_4
- 先检查tomcat是否成功运行(小猿已经修改了http connecter 为9000)
到目前位置tomcat已在计算机上成功安装
tomcat的启动和停止
启动tomcat
进入bin目录下执行以下命令即可启动tomcat。
#tomcat的启动
./startup.sh
#查看tomcat
ps -ef | grep tomcat
说明tomcat已经启动
停止tomcat
#tomcat的启动
./shutdown.sh
#查看tomcat
ps -ef | grep tomcat
tomcat 配置文件的修改
- 将自己的war包扔到tomcat的webapps下
配置tomcat的server.xml文件
配置http访问端口
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="9000" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
配置apj内部端口
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8015" protocol="AJP/1.3" redirectPort="8443" />
不清楚ajp connecter与http connecter的童鞋请看这里。
最后配置默认加载路径
压缩包已准备就绪,server.xml配置已经完毕,现启动tomcat
进入bin,启动tomcat,
./startup.sh
发现tomcat并没有真正的启动起来,反复重启几次依然得到这种结果,果断去查看日志发现:
SEVERE: Parse Fatal Error at line 140 column 19: Element type "Context" must be followed by either attribute specifications, ">" or "/>".
org.xml.sax.SAXParseException; systemId: file:/home/sy/websitedeployment/apache-tomcat-7.0.57_1/conf/server.xml; lineNumber: 140; columnNumber: 19; Element type "Context" must be followed by either attribute specifications, ">" or "/>".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.seekCloseOfStartTag(XMLDocumentFragmentScannerImpl.java:1394)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1324)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
at org.apache.catalina.startup.Catalina.load(Catalina.java:615)
at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
定位到server.xml的140行
Attribute一定要加空格,否则就会报解析错误,另外由于本人的页面放在static中,所以docBase也需要修改。
tomcat默认favicon的修改
再次启动tomcat
访问tomcat后发现默认的favicon并没有修改过来。
将自己项目下的favicon和webapps/root中的favicon替换就行。
最后访问成功
行笔至此,单台tomcat部署页面完毕,若有多台tomcat则按上述方法配置,但最为重要的一点就是记得修改端口,不然会出现无法启动tomcat。
还没有评论,来说两句吧...