Eclipse is by far my favorite IDE, which makes Rational Application Developer bearable. The one thing I’ve been spoiled on in RAD is being able to run the WebSphere Test Environment inside the development environment and be able to have some level of hot deploy when modifying classes or jsp’s in the web project. This brings me to my problem with Eclipse and Tomcat, Eclipse provides great support for adding a Tomcat server to run in your IDE, but the default classpath set up forces you to do a build and restart almost everytime you modify a JSP or Class, this is a real pain. The other pain is that by default when you set up a web project, eclipse decides to build your src files into a build directory rather than just building them directly into the web project’s WEB-INF/classes directory.
This is what I’m here to solve. I’m assuming your using Eclipse 3.2 (Callisto) with the Web Tools installed, JDK 1.5 or 1.6, and Tomcat 5.5 or 6. May work in earlier versions, but I haven’t set up any projects like that recently.
Create a new Dynamic Web Project
- Open Eclipse
- Create a New Web Project
- Open the Java Perspective
- Right click and choose New -> Project
- Under Web Folder Choose Dynamic Web Project Click Next, Click Next
- Under Project Facets choose Dynamic Web Module, Java, Click Next
- Change Context Root to / Click Finish
Change the Build Path
- Right click the Project and choose Properties
- Choose Java Build Path in the Left Panel, Click the Source Tab
- Change the Default output folder to: yourprojectname/WebContent/WEB-INF/classes
- Click OK
Create Tomcat Server
- Right click and choose New -> Other
- Under Server Folder Choose Server Click Next
- Under Apache Choose Tomcat v5.5 Server Click Next
- Under Tomcat installation directory: Browse to the place where you unzipped the Tomcat installation
- Under JRE: Make sure jre1.5.x is selected, you may need to add the jre if a different one is installed on your computer. Click Next
- Choose the project you created from Available projects to Configured projects Click Finish
- Open the Server View, if it’s not displayed already – Window –> Show View–> Other–> Choose Servers under Server
- Save the Perspective so that the Servers View will also be displayed
- The server you just created will appear in the Servers View
- Right Click the server and choose Move to Workspace
- Double click the Server and the Server Overview will be opened.
- Change the Server Name to something meaningful like YourProjectName Server, Save the configuration
- Close the editor and it will ask you if you want to rename the diretory to match the server name, click yes
- Open the server.xml
- Change the appBase attribute of the Host node to contain the absolute path to your workspace directory ex. <Host appBase=”d:\web” autoDeploy=”true” name=”localhost” unpackWARs=”false” xmlNamespaceAware=”false” xmlValidation=”false”>
- Change the port attribute of the Connector node to 80 and the redirectPort attribute to 443
- Change the docBase attribute of the Context Node to contain the absolute path to your WebContent folder ex. <Context docBase=”d:\web\yourprojectname\WebContent” path=”/” reloadable=”true” source=”org.eclipse.jst.j2ee.server:forensicsalvage”/>
You should be able to start the server up from the Server View and view you application and make live changes to your jsp’s, which should only require a refresh now.
http://greatwebguy.com/programming/eclipse/make-eclipse-and-tomcat-play-nice-together/
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
