我正在使用eclipse和tomcat。我正在构建和管理一个web应用程序。我的问题是,为了一个简单的改变,它需要一次又一次地重启服务器,这是相当恼人的。那么,有没有什么方法可以通过tomcat自动部署war,这样更改就可以在不重新启动服务器的情况下生效。我还想更改jsp和java类。请帮帮我。我在这个网站上读了一些问题,但我不能理解它。请给出一步一步的方法。
发布于 2015-08-01 17:12:42
我认为eclipse为你做到了这一点,但我可能错了。我个人在我的构建系统中使用了不同的方法来解决这个问题,因为我不使用eclipse,但是您也可以使用eclipse。
我使用Gradle,它允许我编写任务来移动文件。你也可以用Ant做到这一点。要部署到tomcat,您必须将一个.war文件放到tomcat服务器的webapps文件夹中(这在每个机器上都是不同的)。然后Tomcat获取这个.war文件,打开它,并以相同的名称创建一个目录,在该文件夹中,这是用于显示文件的目录。
要在不需要重启的情况下将您的编辑推送到tomcat,您需要将您的.war移动到webapps文件夹,并清除为您创建的tomcat目录。这仍然会产生一个问题,解压war需要一秒钟的时间,所以另一种方法是直接将新的类和web文件移动到tomcat通过解压缩.war为您创建的文件夹中。我称之为热交换。下面是我用gradle编写的一个任务示例。您可以下载用于eclipse的Gradle Buildship并执行相同的操作。
def tomcat = '/usr/local/Cellar/tomcat/8.0.24/libexec/webapps'
def pNmae = 'myApp'
// Below is a task to move your war to webapps
// deploy your application to your machine.
task devDeploy(type: Copy){
description 'Deploys a war of your plugin to tomcat for local development.'
from archives
into tomcat
include '**/*.war'
}
// Below is code to move the files directly into the directory tomcat makes
// for the quicker viewing of changes in a running tomcat instance
task loadClasses(type: Copy){
description 'Hot swap your tomcat class files directly'
from 'build/classes/main'
into tomcat + '/' + pName + '/WEB-INF/classes'
}
task loadWebFiles(type: Copy){
description 'Load web files into tomcat directly'
from 'src/main/webapp'
into tomcat + "/" + pName
}
task hotswap << {
description 'Swap files in a running instace of tomcat'
tasks.loadWebFiles.execute()
tasks.loadClasses.execute()
}只有当你想使用gradle,或者写一个脚本来做同样的事情时,这个解决方案才能真正对你起作用。我希望这至少能帮助你理解在不重新启动tomcat的情况下,在你的应用程序中渲染更改需要什么。
https://stackoverflow.com/questions/31760069
复制相似问题