簡體   English   中英

如何自動部署tomcat?

[英]How to auto deploy the tomcat?

我在tomcat中使用eclipse。 我正在構建和管理Web應用程序。 我的問題是,它需要一次又一次地重新啟動服務器以進行簡單的更改,這很煩人。 因此,有什么方法可以通過tomcat自動部署戰爭,從而可以在不重新啟動服務器的情況下影響更改。 我也想更改jsps以及java類。 請幫幫我。 我已經在該網站上閱讀了一些查詢,但無法理解。 請逐步說明。

我以為食能為您做到這一點,但我可能是錯的。 我個人使用其他方法在構建系統中解決了此問題,因為我不使用eclipse,但您也可以將其與eclipse一起使用。

我使用Gradle,這使我可以編寫任務來移動文件。 您也可以使用Ant進行此操作。 要部署到tomcat,您必須將.war文件放入tomcat服務器的webapps文件夾中(這在每個人的計算機上都不同)。 Tomcat然后使用此.war文件打開它,並在該文件夾中創建一個具有相同名稱的目錄,這就是用來顯示文件的目錄。

要將編輯內容推送到tomcat而不需要重新啟動,您需要將.war移至webapps文件夾,並清除為您創建的tomcat目錄。 這仍然會產生一個問題,需要花一秒鍾時間來解壓您的戰爭,因此另一種方法是將新類和Web文件直接移到tomcat通過解壓縮.war而為您創建的文件夾中。 我稱之為熱插拔。 以下是我在gradle中編寫的任務的示例。 您可以下載Gradle Buildship for eclipse並執行相同的操作。

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的情況下呈現應用程序中的更改所需的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM