做一些事情,每次Tomcat服务开始通过批处理文件 [英] Do something everytime the Tomcat Service starts through a batch file

查看:339
本文介绍了做一些事情,每次Tomcat服务开始通过批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能修改某个批处理文件为Tomcat这样被设置为一个Web服务将启动会做一些如检查或修改某些文件的Tomcat过吗?

Is it possible to modify a certain batch file for Tomcat such that before Tomcat which is set as a web service will start would do something like checking or modifying some files?

所以,我们要的是每次Tomcat服务启动时,为它是由是由tomcat的托管应用程序所需的一些特定的文件做了一些修改。

So what we want is everytime the Tomcat Service starts, do some modifying for some specific files which is needed by the application which is hosted by tomcat.

如果它可以通过在tomcat的批处理文件中的一个做那么,我们应该修改该批处理文件?任何想法将是非常美联社preciated。顺便说一句,我们使用Tomcat 7。

If its possible to do it by one of the batch files in tomcat then which batch file should we modify? Any ideas would be much appreciated. By the way, we're using tomcat 7.

推荐答案

简短的回答:这是不可能的,至少没有简单的方法来做到这一点,只是因为它是在讨论页面沙善Kadne指出。除了通过的startup.bat 脚本启动Tomcat,并把您code(或您的BAT文件的调用)在 setenv.bat 在同一文件夹文件的startup.bat

Short answer: It is NOT possible, at least there is no easy way to do it, just as it was discussed on the page Shashank Kadne pointed out. Other than starting Tomcat via startup.bat script and placing you code (or a call to your BAT file) in the setenv.bat file in the same folder as startup.bat.

如果你想运行像詹金斯,Artifactory的和都在一个Tomcat安装的应用程序 - 该网页上讨论 - 一个更好的方法是创建一个Tomcat服务器实例(也称为 CATALINA_BASE ),每增加一个应用程序。

If you are trying to run applications like Jenkins, Artifactory and alike on a single Tomcat installation - as discussed on that page - a better way would be to create a Tomcat Server Instance (also known as CATALINA_BASE) for each additional application.

这种方式可以让每个应用程序作为Windows服务,并控制它作为一种服务。

This way you can have each application as a Windows Service and control it as a service.

假设:


  • 您的Java安装在 C:\\ Program Files文件\\的Java \\ jdk的-7.0_03

您的Tomcat安装在 C:\\ Program Files文件\\ Apache的\\ Tomcat 7的

You Tomcat is installed at C:\Program Files\Apache\Tomcat 7.

您想例如詹金斯的服务器是在 C:\\ Program Files文件\\我的詹金斯

You want e.g. Jenkins server to be at C:\Program Files\My Jenkins.

启动的cmd.exe ,然后执行以下操作:

Start cmd.exe, and do the following:

    C:\Users\me> set "JAVA_HOME=C:\Program Files\Java\jdk-7.0_03"
    C:\Users\me> set "CATALINA_HOME=C:\Program Files\Apache\Tomcat 7"
    C:\Users\me> set "CATALINA_BASE=C:\Program Files\My Jenkins"
    C:\Users\me> cd "%CATALINA_BASE%"
    C:\Program Files\My Jenkins> mkdir "%CATALINA_BASE%\bin"
    C:\...Jenkins> mkdir "%CATALINA_BASE%\conf"
    C:\...Jenkins> mkdir "%CATALINA_BASE%\lib"
    C:\...Jenkins> mkdir "%CATALINA_BASE%\logs"
    C:\...Jenkins> mkdir "%CATALINA_BASE%\temp"
    C:\...Jenkins> mkdir "%CATALINA_BASE%\webapps"
    C:\...Jenkins> mkdir "%CATALINA_BASE%\work"
    C:\...Jenkins> copy "%CATALINA_HOME%\conf\*.*" "%CATALINA_BASE%\conf"
    C:\...Jenkins> copy "%CATALINA_HOME%\bin\*.exe" "%CATALINA_BASE%\bin"
    C:\...Jenkins> copy "%CATALINA_HOME%\bin\tomcat-juli.jar" "%CATALINA_BASE%\bin"
    C:\...Jenkins> cd bin
    C:\...Jenkins> ren tomcat7.exe jenkins.exe
    C:\...Jenkins> ren tomcat7w.exe jenkinsw.exe

下一个命令应该在一行

The next command should be in a single line

    C:\...Jenkins> jenkins.exe //IS//Jenkins --DisplayName "Jenkins CI"
      --Description "Jenkins Continuous Integration Server on Tomcat"
      --Startup auto --JavaHome "%JAVA_HOME%" --StartMode jvm --StopMode jvm
      --StartClass org.apache.catalina.startup.Bootstrap
      --StopClass org.apache.catalina.startup.Bootstrap
      --StartParams start --StopParams stop
      --Classpath "%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;"
      --StdOutput auto --StdError auto --LogLevel INFO
      --LogPath "%CATALINA_BASE%\logs"
      --JvmOptions -Xrs;-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;

您现在应该有詹金斯CI 服务在服务窗口。

You should now have the Jenkins CI service in your "Services" window.

部署詹金斯Web应用程序( WAR 文件)到%CATALINA_BASE%\\ web应用

Deploy the Jenkins web application (WAR file) into %CATALINA_BASE%\webapps.

我上面给的从头现身,未经测试的步骤,我可能会错过一个或两个参数。这就是为什么有是%CATALINA_BASE%\\ BIN \\ jenkinsw.exe - 启动和调整参数,直到服务器的工作。

The steps I gave above are coming "from the the head" and are not tested, I might have missed a parameter or two. That is why there is the %CATALINA_BASE%\bin\jenkinsw.exe - start it and tweak the parameters until the server is working.

这篇关于做一些事情,每次Tomcat服务开始通过批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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