Guide to Downloading, Configuring Tomcat, and Integrating with Jenkins

Guide to Downloading, Configuring Tomcat, and Integrating with Jenkins

Downloading and Configuring Tomcat:

  1. Download Tomcat:

    Search for the latest version of Tomcat on Google and obtain the download link. For example, you can find the link at https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.19/bin/apache-tomcat-10.1.19.tar.gz.

  2. Navigate to Opt Directory:

     sudo su -
     cd /opt
    
  3. Download and Extract Tomcat:

     wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.19/bin/apache-tomcat-10.1.19.tar.gz
     tar -xvzf apache-tomcat-10.1.19.tar.gz
    
  4. Rename Tomcat Directory:

     mv apache-tomcat-10.1.19 tomcat
    
  5. Start Tomcat Server:

     cd /opt/tomcat/bin
     ./startup.sh
    
  6. Access Tomcat Manager:

    Open a web browser and navigate to public_ip:8080. Ensure that port 8080 is open in the security group of your instance.

  7. Update Context Configuration:

    After receiving a 403 error when accessing the manager app, update the context.xml files:

     find / -name context.xml
     vi /opt/tomcat/webapps/host-manager/META-INF/context.xml
     vi /opt/tomcat/webapps/manager/META-INF/context.xml
    

    Comment out the lines containing <Valve class ...> by adding <!-- at the beginning and --> at the end.

  8. Configure Users for Manager App:

     cd /opt/tomcat/conf/
     vi tomcat-users.xml
    

    Add the following users:

     <role rolename="manager-gui"/>
     <role rolename="manager-script"/>
     <role rolename="manager-jmx"/>
     <role rolename="manager-status"/>
     <user username="admin" password="admin@4253" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
     <user username="deployer" password="deployer" roles="manager-script"/>
     <user username="tomcat" password="s3cret" roles="manager-gui"/>
    
  9. Restart Tomcat:

    Create symbolic links for startup and shutdown scripts:

     ln -s /opt/tomcat/bin/startup.sh /usr/local/bin/tomcatup
     ln -s /opt/tomcat/bin/shutdown.sh /usr/local/bin/tomcatdown
    

    You can now start and stop Tomcat using tomcatup and tomcatdown.

Integrating Tomcat with Jenkins:

  1. Install "Deploy to container" Plugin:

    • Log in to Jenkins UI.

    • Navigate to Manage Jenkins > Manage Plugins > Available.

    • Search for "Deploy to container" and install it without restarting.

  2. Add Credentials:

    • Go to Credentials > System > Global credentials (unrestricted) > Add credentials.

    • Choose Username with password.

    • Enter the following details:

      • Username: deployer

      • Password: (Provide the password)

      • ID: tomcat_deployer

      • Description: Use this credentials to deploy artifacts on Tomcat server

  3. Create Jenkins Job:

    • Name: DemoDeployOnTomcat

    • Select Maven Project.

    • SCM: Git (Add your repository URL)

    • Build:

      • Root POM: pom.xml

      • Goals and options: clean install

  • Post Build Actions:

    • Deploy war/ear to container

      • WAR/EAR files: **/*.war (Artifact built by Maven)

      • Containers: Tomcat 9.x Remote

  1. Build Jenkins Job:

    Trigger the Jenkins job to build the project.

  2. Verify Deployment:

    • Go to the Tomcat server's manager app.

    • Navigate to "List apps" and verify the deployed web application.

Following these steps will ensure the smooth setup and integration of Tomcat with Jenkins, allowing for efficient deployment of artifacts.