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

  • Home
  • SEARCH
  • 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 557319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:00:50+00:00 2026-05-13T12:00:50+00:00

OK, I’m completely stuck. I want to run Tomcat in embedded mode so I

  • 0

OK, I’m completely stuck. I want to run Tomcat in embedded mode so I can test an application without running the server in a separate process. I’m missing something simple, stupid, and important, and I need your help to see it.

This test fails with an HTTP error 400, Bad Request. I’ve tried MemoryProtocolHandler, context.invoke(), … I don’t know what to do. Maybe you see something simple.

package ca.jbrains.jsfunit.learning.test;

import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.MemoryRealm;
import org.apache.catalina.startup.Embedded;
import org.junit.After;
import org.junit.Test;

import com.gargoylesoftware.htmlunit.WebClient;

public class LearnEmbeddedTomcatTest {
    private Embedded embedded;
    private Container host;
    private Engine engine;

    @Test
    public void deploySampleApplicationFromFileSystem() throws Exception {
        String tomcatPath = "/Users/jbrains/ThirdParty/apache-tomcat-5.5.28-embed";

        // Create an embedded server
        embedded = new Embedded();
        embedded.setCatalinaHome(tomcatPath);
        embedded.setRealm(new MemoryRealm());

        // Create an engine
        engine = embedded.createEngine();
        engine.setDefaultHost("localhost");

        // Create a default virtual host
        host = embedded.createHost("localhost", tomcatPath + "/webapps");
        engine.addChild(host);

        // Create an application context
        Context context = embedded.createContext("TddJsfWeb", tomcatPath
                + "/webapps/TddJsfWeb");
        host.addChild(context);

        // Install the assembled container hierarchy
        embedded.addEngine(engine);

        // Assemble and install a default HTTP connector
        Connector connector = embedded.createConnector("localhost", 8080,
                "http");
        embedded.addConnector(connector);

        // Start the embedded server
        embedded.setAwait(true);
        embedded.start();

        WebClient webClient = new WebClient();
        webClient.getPage("http://localhost:8080/TddJsfWeb/static.xhtml");
    }
}

The unpacked .war is definitely at /Users/jbrains/ThirdParty/apache-tomcat-5.5.28-embed/webapps/TddJsfWeb/... and static.xhtml is in the root of the unpacked .war folder.

Please, please, show me how stupid I am. Thanks.

  • 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-05-13T12:00:50+00:00Added an answer on May 13, 2026 at 12:00 pm

    I’d like to second Jetty over Tomcat for this.. To run Jetty all I need is:

    import java.awt.Desktop;
    import java.io.IOException;
    import java.net.URI;
    import java.net.URISyntaxException;
    
    import org.mortbay.jetty.Connector;
    import org.mortbay.jetty.Server;
    import org.mortbay.jetty.bio.SocketConnector;
    import org.mortbay.jetty.webapp.WebAppContext;
    
    public class StartJetty {
           public static void main(String[] args) throws Exception {
                   Server server = new Server();
                   SocketConnector connector = new SocketConnector();
                   // Set some timeout options to make debugging easier.
                   connector.setMaxIdleTime(1000 * 60 * 60);
                   connector.setSoLingerTime(-1);
                   connector.setPort(8081);
                   server.setConnectors(new Connector[] { connector });
    
                   WebAppContext bb = new WebAppContext();
                   bb.setServer(server);
                   bb.setContextPath("/");
                   bb.setWar("src/main/webapp");
                   server.addHandler(bb);
    
                   try {
                           System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY
    KEY TO STOP");
                           server.start();
    
                           //Launch browser
                           if (Desktop.isDesktopSupported())
                                   if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))
                                           try {
                                                   Desktop.getDesktop().browse(new URI("http://localhost:8081/"));
                                           }
                                           catch (IOException ioe) {
                                                   ioe.printStackTrace();
                                           }
                                           catch (URISyntaxException use) {
                                                   use.printStackTrace();
                                           }
    
                           System.in.read();
                           System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
                           server.stop();
                           server.join();
                   }
                   catch (Exception e) {
                           e.printStackTrace();
                           System.exit(100);
                   }
           }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.