Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8888215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:58:58+00:00 2026-06-14T21:58:58+00:00

I have a Maven-based web app project that generates a WAR to be run

  • 0

I have a Maven-based web app project that generates a WAR to be run in Tomcat. Let’s suppose, for the sake of argument, that it’s vitally important for that project’s unit tests to actually send/receive requests over the network (rather than simply calling servlet methods with a mock request).

Is there any way for my test harness to run an instance of Tomcat in the same JVM, load the current project, and let the test cases hit it on localhost? Failing that, how would I actually programatically package the current project (along with dependencies) into a WAR so that I could use Cargo to upload it programatically to some other Tomcat instance? Is there any better alternative than just shelling out to mvn?

I know my request is unusual and unit tests should be more self-contained, etc, but please let’s just play along 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:58:59+00:00Added an answer on June 14, 2026 at 9:58 pm

    You can use an embedded Tomcat for exactly this purpose. Simply set up a static instance in your test harness, and shut it down at the end. Here’s some sample code:

    import org.apache.catalina.LifecycleException;
    import org.apache.catalina.startup.Tomcat;
    import org.junit.AfterClass;
    import org.junit.BeforeClass;
    
    public class TomcatIntegrationTest {
      private static Tomcat t;
      private static final int TOMCAT_PORT = 9999;
    
      @BeforeClass
      public static void setUp() throws LifecycleException {
        t = new Tomcat();
        t.setBaseDir(".");
        t.setPort(TOMCAT_PORT);
        /* There needs to be a symlink to the current dir named 'webapps' */
        t.addWebapp("/service", "src/main/webapp"); 
        t.init();
        t.start();
      }
    
      @AfterClass
      public static void shutDownTomcat() throws LifecycleException {
        t.stop();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Maven based Spring-WS client project that I want to package as
I have a maven-based GWT project that includes Guava. I am running into trouble
I have a maven based mule project that was original created with mule version
This is the thing ... I have my Maven web project based on spring3.0
I have a web app that depends on multiple internal maven projects, can one
I have maven-plagin and need to run goal, that should automatically run before plugin.
I have a maven project that contains a certain api I need to use
I have a pom file that looks similar to this <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
I have a Maven project which generates a 413.06 KB jar file. I have
We are 4 developers working on a maven-based java web project . We each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.