Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Setting Up Apache Tomcat 8.5 Source Code in IntelliJ IDEA with Maven

Notes 1

Downloading Tomcat Source Code

Clone the Tomcat 8.5.x branch from the official Apache repository:

git clone https://github.com/apache/tomcat.git

Switch to the 8.5.x branch for compatibiilty with this setup.

Creating the Maven POM File

Add a pom.xml to the root of the cloned repository with the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>Tomcat85</artifactId>
    <name>Tomcat 8.5</name>
    <version>8.5</version>

    <build>
        <finalName>apache-tomcat-8.5</finalName>
        <sourceDirectory>java</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <resources>
            <resource>
                <directory>java</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>test</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.5.1</version>
        </dependency>
    </dependencies>
</project>

If compilation fails due to a problematic test class, remove it from the test directory.

Setting Up the Caatlina Home Directory

Create a new directory called catalina-home and copy the following from the Tomcat source:

  • webapps/ folder
  • conf/ folder

Create these empty subdirectories inside catalina-home:

  • temp/
  • logs/
  • lib/

Configuring Run Configuration in IntelliJ IDEA

Create a new Application run configuration with these VM options:

-Dcatalina.home=catalina-home
-Dcatalina.base=catalina-home
-Djava.endorsed.dirs=catalina-home/endorsed
-Djava.io.tmpdir=catalina-home/temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=catalina-home/conf/logging.properties

Set the main class to:

org.apache.catalina.startup.Bootstrap

The VM options ensure the Tomcat instance uses the configured catalina-home directory for runtime operations.

Resolving NullPointerException on First Access

When accessing Tomcat through the browser for the first time, a NullPointerException may occur. To fix this, locate the ContextConfig class and add the Jasper initializer in its initialization logic:

context.addServletContainerInitializer(new JasperInitializer(), null);

This registers the JSP compiler container initializer during the web application context setup phase.

Running the Application

Execute the run configuration created earlier. Tomcat will start and listen on the configured ports (default: 8080 for HTTP, 8005 for shutdown).

Tags: tomcat

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.