Building & Launching Java Web Apps in IntelliJ

Two women working together on a project

Building & Launching Java Web Apps in IntelliJ

In the ever-evolving landscape of web development, building robust and efficient web applications has become a paramount endeavor. Developers are constantly seeking tools and methodologies that streamline the development process and empower them to craft seamless user experiences. In this pursuit, Apache Maven has emerged as a versatile build automation and project management tool that plays a pivotal role in simplifying the creation of web applications.

IntelliJ IDEA, on the other hand, stands as one of the most popular integrated development environments (IDEs), renowned for its feature-rich environment and exceptional support for various programming languages and frameworks. When combined with the power of Maven, IntelliJ offers developers a potent synergy that catalyzes the development of dynamic and scalable web applications.

In this article, we embark on a journey to explore the amalgamation of Maven and IntelliJ IDEA, unraveling the intricate process of creating web applications that adhere to best practices in both architecture and development. Whether you’re a seasoned developer aiming to enhance your skills or a newcomer eager to grasp the fundamentals, this guide aims to provide you with a comprehensive walkthrough of leveraging Maven within the IntelliJ ecosystem.

Embarking on the Journey of Web Application Crafting

The realm of web application crafting encompasses the intricate process of conceiving and upkeeping software applications that seamlessly unfold their functionality over the vast expanse of the internet, readily accessible through the vessel of web browsers. These digital marvels can span from rudimentary online domiciles to intricate, dynamic platforms that orchestrate a symphony of services and interactions for their users. The domain of web application development has woven itself into the very fabric of our contemporary technological panorama, driven by the ubiquitous sway of the internet and the surging appetite for virtual amenities. This intricate art empowers both enterprises and individuals to cast their nets wide, capturing a global audience, granting expeditious passage to information and utilities, all while orchestrating user engagement through channels of innovation.

Pervasive Eminence within the Modern Technological Canvas:

  • Global Reach: These digital enclaves can be ventured upon from any nook and cranny of the world, extending their hospitable embrace to users traversing diverse geographies and wielding an array of electronic apparatus;
  • Expandability: The innate architecture of web applications lends itself seamlessly to augmentation, accommodating the escalating throngs of users with grace, all devoid of the need for monumental infrastructural reconfigurations;
  • Universality in Compatibility: Web applications gracefully traverse a plethora of devices and operating systems, subduing the necessity for bespoke development endeavors targeted at specific platforms;
  • Economical Viability: The development and deployment of web applications are executed with fiscal finesse, eschewing the conventional labyrinthine software pathways entailing device-specific installations or recurrent updates;
  • Expedited Craftsmanship: The tapestry of frameworks and tools has metamorphosed, culminating in the streamlining of web application fabrication; thereby, bequeathing developers with the capability to conjure and refine applications at an accelerated pace;
  • Uninterrupted Evolution: The dynamic pulse of web applications entails perpetual enhancements, seamlessly unfurling without imposing the chore of manual updates upon users, thus engendering a milieu of fluid user experiences.

Crafting a Web Application using Maven in IntelliJ

This comprehensive tutorial is designed to guide you through the process of creating a dynamic web application using the Maven build tool within the IntelliJ Integrated Development Environment (IDE). It is assumed that you have Maven installed on your local machine. If not, you can refer to our guide on installing Maven on Windows for a seamless setup.

Choosing the Framework: Java 8 and IntelliJ Community Edition Version 2020.1.1

For the purpose of this illustrative example, we’ll employ Java 8 as the programming language and the IntelliJ Community Edition Version 2020.1.1 as the IDE. This powerful combination lays the foundation for creating a robust web application.

Initiating the Project: A Step-by-Step Guide

Commence your journey by launching IntelliJ and directing your attention to the process of initializing a new project:

  1. After opening IntelliJ, navigate to “Create New Project.”;
  2. On the left-hand side, opt for “Maven” as the project type;
  3. Choose the appropriate Project Software Development Kit (SDK) or define a new one by specifying the Java Development Kit (JDK) folder path;
  4. For a streamlined setup, you can leverage an archetype template to preconfigure your pom.xml file, or you can exercise full control by crafting your own pom.xml later. For the sake of expediency, let’s select “Create from archetype” and opt for “org.apache.maven.archetypes:maven-archetype-webapp.”;
  5. Proceed by clicking “Next,” then supply the GroupId and ArtifactId. Typically, GroupId represents the company or organization’s name, while ArtifactId designates the project’s name. A subsequent click on “Next” advances you to the next phase of project creation;
  6. A window will emerge, presenting you with options regarding the Maven installation to utilize. By default, IntelliJ is equipped with a Bundled Maven installation, which can be used for convenience, or you can opt for a separate Maven installation if desired. After making your selection, click “Next.”;
  7. Validate the project name and its designated location, and subsequently click “Finish.”;
  8. If prompted, opt to “Enable Auto Import” for automatic integration of Maven dependencies.

Navigating Your Project Structure

With the initial setup in place, familiarize yourself with the project’s structural framework:

Upon successful completion, your project’s structure will mirror the following example. To visualize this hierarchy, click on the “Project” tab located on the left side of the interface. If the “Project” tab is not visible, reveal it by clicking the double-square icon positioned at the lower-left corner of the IntelliJ window.

Laying the Foundation: Folder Structure Configuration

In the event that IntelliJ has not created the designated “java” and “resources” folders for your project, follow these steps to manually introduce them:

  • Right-click on the main project folder;
  • From the context menu, select “New” and subsequently choose “Directory.”;
  • Name the new directory “java” and confirm;
  • Repeat the process to create the “resources” folder;

Your revised folder structure should resemble the following:

Fine-Tuning the Project Configuration: Modifying pom.xml

Given that we initiated the project using an archetype, IntelliJ has already injected a default configuration for launching a web application. Let’s enhance this setup by customizing the XML configuration:

Open the pom.xml file.

Locate the entries for “maven.compiler.source” and “maven.compiler.target,” both of which pertain to the Java version. Update the version to “1.8” to ensure compatibility with Java 8.

<properties>

  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  <maven.compiler.source>1.8</maven.compiler.source>

  <maven.compiler.target>1.8</maven.compiler.target>

</properties>

Progressing to the “build” section, insert the Jetty plugin. This plugin acts as the web application container, akin to Tomcat, JBoss, and Glassfish.

<plugins>

    <!– Jetty Plugin. Default port is 8080 –>

    <plugin>

        <groupId>org.eclipse.jetty</groupId>

        <artifactId>jetty-maven-plugin</artifactId>

        <version>9.4.28.v20200408</version>

    </plugin>

</plugins>

Finalizing the Configuration: Your Comprehensive pom.xml

With the alterations incorporated, your refined pom.xml will resemble this:

<!– Your complete pom.xml content –>

code

Launching Your Web Application: Deploying and Running

Elevate your project to the next level by executing the deployment and running process:

  • Expand the “Maven” tab;
  • Within “Maven Projects,” unfold your web application project, then explore the “plugins” section;
  • Navigate to the Jetty plugin and initiate the process by double-clicking on “jetty:run.”;
  • Stay attentive to the IntelliJ console, where you’ll be greeted by the message “Started Jetty Server” upon successful deployment. To visualize your web application, launch your browser and access “localhost:8080.”

Debugging with Precision

For debugging capabilities, enhance your development workflow by following these steps:

  • Right-click on “jetty:run.”;
  • Select the “debug” option, which initiates both project deployment and debugging features simultaneously.

Troubleshooting: Overcoming Potential Issues

In the event that you encounter an error message regarding a “Bad temp directory from Jetty,” employ this strategy to overcome the obstacle:

  • Begin by performing a clean installation of your web application. Access the “Lifecycle” option within the “Maven” tab and select “clean install.”;
  • After the installation process, rerun the Jetty server by clicking “jetty:run.”;
  • By following these comprehensive guidelines, you’ll harness the prowess of Maven and IntelliJ to craft a dynamic web application, facilitating seamless development, customization, and debugging.

Conclusion

In conclusion, mastering the art of creating web applications using Maven in IntelliJ can significantly elevate your development capabilities and streamline your project workflows. Throughout this article, we’ve delved into the essential steps, concepts, and best practices that empower developers to efficiently build robust and scalable web applications.

In your journey to master the creation of web applications using Maven in IntelliJ, remember that practice, experimentation, and ongoing learning are key. Embrace the principles outlined in this article, adapt them to your unique projects, and remain open to exploring new techniques and emerging technologies. By doing so, you’ll not only enhance your development prowess but also contribute to the dynamic and ever-expanding realm of web application innovation.