当我在Eclipse中的tomcat上运行应用程序时会发生什么 [英] What happens when I run an application on tomcat in Eclipse

查看:137
本文介绍了当我在Eclipse中的tomcat上运行应用程序时会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用eclipse和tomcat服务器进行java web应用。我想知道当我在Tomcat上运行我的网站时会发生什么?在tomcat上运行应用程序时Eclipse执行的步骤是什么。



这将有助于我了解何时关闭服务器(调试时)/何时清除服务器等。



我需要知道什么进入服务器,以便我可以在调试时更好地。



现在我所做的一切都是重新启动服务器,每当出现问题。我浪费了足够的时间做这个。我想我需要多花点时间了解幕后发生的情况。

解决方案

环境假设



我会假设:




  • target / classes 是编译类的目标文件夹

  • src / main / webapp 是Web应用程序内容文件夹

  • 项目>自动建立选项



部署目录



Eclipse正在使用分解的WAR部署 - 即部署的应用程序部署为文件夹,而不是单个文件存档。应用程序文件从 $ {workspace} /。metadata / .plugins / org.eclipse.wst.server.core / tmp0 / wtpwebapps / 放置和加载。



发布



发布是负责组装和部署Web应用程序的中心过程。在谈论本地的Tomcat时,这意味着将web内容,编译的类,库,...复制到部署目录( .metadata )。



Eclipse能够进行部分发布 - 即当单个资源更改(例如某些JSP)时,Eclipse将仅发布该单个文件。



默认情况下,一些资源更改时会自动执行发布过程。这可以在服务器设置中进行修改(双击服务器视图中的服务器名称)。





更改静态资源



如果你改变,说 src / main / webapp / resources / myApp / css / main.css




  • 发布文件被复制到部署文件夹

  • 资源立即可用于服务器客户端



更改JSP文件



如果更改JSP文件:




  • 发布文件被复制到部署文件夹

  • Tomcat注意到JSP文件已更改并重新编译

  • 更改JSP可以呈现内容



更改Java文件



如果您更改了java源文件:




  • 该文件被编译成目标/类

  • 发布该文件被复制到部署文件夹

  • Tomcat (不免费)。



    清理



    部署的应用程序可能会损坏。值得注意的是,当您要清理完整编译和发布的资源时,您应该:




    • 清理编译的类( Project> Clean ... - 删除 target / classes

    • 文件(服务器>清理... - 删除部署文件夹)

    • 清理Tomcat工作目录(服务器>清理Tomcat工作目录... - 删除编译的JSP)


    I am making a java webapplication using eclipse and tomcat server. I want to know what happens when I run my website on Tomcat ? What are the steps Eclipse does in the background to run the application on tomcat.

    This will help me understand when to switch off the server (while debugging) / when to clean the server etc.

    I need to know what goes into the server so that I can get better at debugging.

    Right now all I do is restart the server everytime something goes wrong. I have wasted enough time doing that. I guess I need to invest a little bit more time in understanding what happens behind the scenes.

    解决方案

    Environment assumptions

    I will assume:

    • target/classes is the target folder for compiled classes
    • src/main/webapp is the web application content folder
    • Project > Build Automatically option is checked

    Deployment directory

    Eclipse is using exploded WAR deployment - i.e. the deployed application is deployed as a folder, not a single file archive. Application files are placed and loaded from ${workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/.

    Publishing

    Publishing is a central process which is responsible for assembling and deploying the web application. When talking about local Tomcat, this means copying "web content, compiled classes, libraries, ..." into deployment directory (the one in .metadata).

    Eclipse is able to do partial publishing - i.e. when a single resource changes (e.g. some JSP), Eclipse will publish only that single file.

    By default publish process is performed automatically when some resource changes. This can be modified in server settings (double click on the server name in Servers view).

    Changing static resource

    If you change lets say src/main/webapp/resources/myApp/css/main.css:

    • upon publish the file gets copied to the deployment folder
    • resource is instantly available to server clients

    Changing JSP file

    If you change JSP file:

    • upon publish the file gets copied to the deployment folder
    • Tomcat notices that the JSP file has changed and recompiles it
    • changed JSP is ready to render content

    Changing Java file

    If you change a java source file:

    • the file gets compiled into target/classes
    • upon publish the file gets copied to the deployment folder
    • Tomcat notices that a class file was changed and reloads the context (i.e. web application is restarted)

    You can turn of the auto-reloading feature in server settings on the Modules tab. Without auto-reloading you can still use hot swap feature, which is able to replace code in running JVM. This is possible only when method signatures are not changed.

    If you want more advanced solution (i.e. not limited to changing just a method body) when it comes to reloading java changes, you should check projects like JRebel (not free).

    Cleaning

    Deployed application can get corrupted. It is worth noting, that when you want to clean completely compiled and published resources, you should:

    • Clean the compiled classes (Project > Clean... - deletes target/classes)
    • Clean the deployed files (Server > Clean... - deletes deployment folder)
    • Clean Tomcat working directory (Server > Clean Tomcat Work Directory... - deletes compiled JSPs)

    这篇关于当我在Eclipse中的tomcat上运行应用程序时会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆