We lighten the weight of the application when deploying to the Apache Tomcat application server

    Very often, the weight of the application that we put on the server reaches indecently large sizes due to the inclusion of all the necessary dependencies in it. My application ultimately takes from 20 to 50 meters. Deploying such wars to a remote server, to Tomcat, is not just a matter of minutes, but when communication is poor, it becomes completely problematic. Putting a library in $ {tomcat.home} / lib is a very thankless and often dangerous thing. We googled a little and found a very pleasant solution on DZone. I want to share with you ...

    I want to say right away that the method is primarily suitable for those who breed their cats, and do not use the services of hosters ... although, it all depends on which hoster offers a solution.

    One person, a certain Dapeng Liu, having carefully read the Tomcat API documentation, implemented a very library, which can be taken here . In fact, the library is an implementation of an application loader for a cat.

    How it works:
    1. Put this library in $ {tomcat.home} / lib
    2. A repo folder is created in $ {catalina.home}. It creates folders with repositories. For example, when hibernate is used, there is a dependency on several libraries at once. We create the directory $ {catalina.home} /repo/hibernate_3.3.0, into which we add all the necessary libraries. You can create a repository immediately for a specific project and put all the necessary libraries there at once.
    3. Correct the context description for your application. Now it should look like this:
      <Context path="/testapp">
      <Loader className='com.spiralcomms.tomcat.WebappLoader' />

    4. The application will be deployed by the specified loader. When the deployment starts, the loader will look in the context for all lib tags, find repositories in the $ {catalina.home} / repo folder and include them in the download

    Thus, applications dramatically lose weight from 20-50 meters to one and a half to two, which indescribably affects the speed of its upload to the server.

    Of course, such a process places a constraint on the developer. When laying out applications, he should know if any libraries have been added to the application in order to update the repository.

    Personally, the method helps me a lot when there is a weak channel to the server and there is a lot of work with the customer regarding the application changes. It is required to make edits and upload them to the server up to 20 times a day.

    PS The original description of the solution found can be found here .

    Also popular now: