您的位置:首页 > 运维架构 > Tomcat

eclipse-tomcat发布java web项目 解决404

2016-04-20 12:25 543 查看
1,最简单的方式就是直接右击项目,然后run as。。

2,在eclipse中安装tomcat插件,之后会有这个图标:



,点击第一个,那么tomcat就会启动。

3,进入tomcat目录下的\conf\Catalina\localhost目录,新建项目名.xml文件,格式如下:

<!--

Context configuration file for the Tomcat Administration Web App

$Id: admin.xml,v 1.2 2002/07/23 12:13:05 remm Exp $

-->

<Context path="/SpringLingerUI" docBase="D:\Projects\SpringLingerUI\WebContent"
debug="0" privileged="true">

<!-- Uncomment this Valve to limit access to the Admin app to localhost
for obvious security reasons. Allow may be a comma-separated list of
hosts (or even regular expressions).
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127.0.0.1"/>
-->

</Context>
其实就是一个context的标签。path就是“/项目名”,docBase就是项目的webcontent目录,设置好这两个变量就可以了。

然后再点击tomcat图标运行就可以访问了。

4,不过我自己在运行的时候却无法刚问,报了404。仔细查看发现,我的项目的源文件夹下的webconten/met-inf没有classes文件夹,也就是编译后的文件不在应该在的位置。然后我查看了项目源目录下的.classpath文件,如下:



最后的output项的path指向的路径,就是这个项目最终编译后的路径,这个明显不是我们想要的,把它改为


最后重启eclipse,就可以访问了。

那么如何在项目最开始就设置output目录为webcontent下呢?

新建dynamic web project的时候,不要填完项目名就直接点击finish,而是点击next,会有如下:



把这里改为webconten下的class文件夹即可。

当然如果是已经存在的项目,也是可以修改这个output目录的,右击项目,然后选择Buil path,选择source选项卡,如下图:



至此,使用eclipse的tomcat插件发布java web项目就完成了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: