<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>前提:环境搭建</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>Jdk1.6.0+Tomcat7.0+Eclipse 4.2.0</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>安装路径:</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>C:JavaJdk1.6.0</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>C:JavaJre1.6.0</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>C:\Program Files\Tomcat 7.0.11</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>E:workspace 我的Eclipse的工作台</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>E:Eclipse/Eclipse.exe<wbr><wbr><span></span>Eclipse所在目录</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>第一种<wbr><wbr><span></span>把项目打包成*.War文件。比如:在Eclipse里,先创建项目login1,然后复制login1并改名为login2,增加或者修改 login2里的类文件后,为了测试下能否实现某功能,就在login2项目上,选择"Export" , 导出为WAR文件,比如命名为login2.War,然后复制这个</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>login2.WAR文件到C:Tomcat 7.0.11webapps下,停止Tomcat服务,重新启动Tomcat服务,login2.war会自动解压出一个文件夹login2,再打开http://127.0.0.1:8080/login2/index.jsp就可以访问了,测试能否实现某功能。这个方法的缺点是,如果需要修改源代码,必须重新打包修改后的war文件,复制到C:Tomcat 7.0.11webapps下并覆盖原来的login2.war,如果需要修改很多次,就需要覆盖很多次,无意义的工作很多,最好是Eclipse里每修改下 源代码,重启TOMCAT服务就可以加载新代码测试,怎样实现了,请参看第二种方法。
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>第二种<wbr><wbr><span></span>要实现的目标就是让ECLIPSE自动部署项目到tomcat的C:Tomcat 7.0.11webapps下,而不是到工作区下的.metadata.pluginsorg.eclipse.wst.server.core tmp1wtpwebapps,可以实现,方法很简单。</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>新建个Dynamic Web Project,命名为mysql,在WebContent下,新建个文件index.jsp,随便写段代码,</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
见图一
点击mysql项目名,然后点击右键Run As—》Run on Server,按照图二
的样式,点击 Next,再点Finish,见图三
Servers下,已经添加好了一个Tomcat v7.0 Server,在上面点右键,选择open,打开,见图四
Server Locations 的状态为灰色,修改不了,见图五
关键就是需要修改这里,那么怎么能修改呢?先要移除掉部署在其中的项目,见图六
Server Locations 的状态不为灰色可修改,见图七<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>配置修改3个地方:</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>1、选择"Use Tomcat installation ",默认为"Use<wbr><wbr>Workspace metadata<wbr><wbr>",见图八;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>2、选中"Use Tomcat insallation "后,下面一行,Server Path 自动修改为C:\Program Files\Tomcat 7.0.11(Tomcat安装路径)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span></span>3、Deploy Path 处需要修改为"webapps" ,默认为"wtpwebapps"。</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
文件修改完,点击close,关闭。弹出对话框,选择YES,保存设置。
至此,设置完成,以后复制一个项目,只需在项目mysql,右键,选择Properties,再选择Web Project Settings修改下项目名称就可以自动部署到Tomcat的Webapps目录下了。见图九。