linux部署web项目到tomcat下(图文详解)

家好,相信不少初学者不知道如何将windows eclipse下开发的web项目部署到linux系统的tomcat下,今天我将图文并茂教大家
首先呢,比如我新建一个web项目,打开eclipse编辑器,创建一个Test项目,
<img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215127770?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
目录结果如上,我在WebContent上创建一个welcome.jsp,里面输入一句话,欢迎大家部署项目到linux
<img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215141609?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
好的,到这里我们的web项目已经建好,
首先我要将项目导出war包,现在有的同学可能有疑问,何为war包,现在我给大家讲解一下,war包其实就是和zip,giz一样的压缩包,是eclipse为大家提供的,一种tomcat,webapps下能够识别的压缩包,当tomcat项目第一次启动的时候会解压war包,如果第二次启动的时候发现该war包已经被解压,将不会再次解压。
好,下面我给大家演示如何在eclipse下导出war包:
<span style="font-size: 18px;">第一步:</span>
<span style="font-size: 18px;">选中项目,点击鼠标右键,选择导出,我这个是中文版本的:</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215240370?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">第二步,</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215254229?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215302881?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">在这里最好不好导出源文件,因为web工程也好,java工程也好,最后都会将.java文件编译成.class文件,.java文件是不起作用的。</span>
<span style="font-size: 18px;">这里点击完成,就等着它导出完成就行了,</span>
<span style="font-size: 18px;">好现在我们就导出成功了,我们打开桌面的war包,</span>
<span style="font-size: 18px;">结果如下,直接用好压打开</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215348959?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">这里我们和打包前的目录对比一下,看有什么不同</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215419893?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">我们可以看到,war包里得目录不包括.settings build  src .classpath .project,WebContent这些文件夹</span>
<span style="font-size: 18px;">其实war包里的东西就是WebContent下的东西,只不过相当于把build及其子文件夹移动到Web-INF下了,我们可以看下WEB-INF:</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215434581?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">和我们猜想的一样,在web开发过程中,会经常提到一个词,叫做类路程,项目类路径,就是classpath,那么什么是classpath呢,</span>
<span style="font-size: 18px;">其实war包里  WEB-INF/classes/这个路径就是项目类路径,根路径。这下大家明白了吧。</span>
<span style="font-size: 18px;">好上面两部讲过了,如何打war包及war包是什么,下面,我们继续讲如何讲war包部署到linux的tomcat下并运行:</span>
<span style="font-size: 18px;">首先,要准备linux操作系统,和tocmat服务器,这些知识我在这里就不多讲了。</span>
<span style="font-size: 18px;">大家看我的环境:</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215530354?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">linux环境版本64为,4.3.4系统,当然你的linux不管是什么系统都可以,不管是红帽还是其他的,</span>
<span style="font-size: 18px;">看下我的tomcat目录:</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215559080?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">现在我们要将war包上传到,webapps下,可以用ssh工具,我打开ssh工具,</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img alt="委屈" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215645620?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">我们通过ssh工具,直接将项目拖到webapps下面,现在我们的操作准备的差不多了。</span>
<span style="font-size: 18px;">在这里,初学者经常会遇到8080端口被占用,或者tomcat启动等一系列错误,</span>
<span style="font-size: 18px;">那么我们如何解决端口被占用的问题,很简单一个命令搞定。现在我们看一下:</span>
<span style="font-size: 18px;">在任何地方,输入命令:ps -aux|grep tomcat,不知道这个命令什么意思的就记住就行了,他就是查看当前服务器有几个tomcat进程的,现在我们看到我的</span>
<span style="font-size: 18px;">服务器有三个tomcat,但是各个端口号我配的都不一样,所以不妨碍,现在我们看到tomcat5-2在运行中,</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215729474?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">我们需要到tomcat5-2的bin目录下调用./shutdown.sh命令将tomcat关闭,然后再来杀掉他的进程,</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215807213?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">在运行ps -aux|grep tomcat发现他还是存在的,这时候我们用kill杀掉该tomcat对应的进程,我们看到上图中,我的tomcat中对应的进程是6785</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215849063?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">就可以了。如果kill不好使的话,用kill -9就可以将其彻底干掉,</span>
<span style="font-size: 18px;">现在我们就可以进入到bin目录下调用./startup.sh来启动项目了:</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215914689?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>
<span style="font-size: 18px;">然后进入到logs目录下,输入下面的命令:tail -f catalina.out</span>
<span style="font-size: 18px;"><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="http://blog.csdn.net/wangyonglin1123/article/details/44960875" alt="" style="border: none; max-width: 100%;" /><img src="https://img-blog.csdn.net/20151226215946498?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" style="border: none; max-width: 100%;" />
</span>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值