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 8004867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:03:14+00:00 2026-06-04T17:03:14+00:00

I am a newbie at web development, and at using embedded jetty. The source

  • 0

I am a newbie at web development, and at using embedded jetty. The source code presented below is developed using eclipse IDE.
I have to start the jetty server programmtically, I do not have an option of starting it via the command line. It needs to be an extremely light weight web interface as it will be launched from a system with low memory/processing speed.

I have developed the following directory structure in ECLIPSE

  JettyExample <Project>
    src 
     sample_package
        HelloWorld.java
     WEB-INF
      index.html
      web.xml

The source code of HelloWorld.java

 public static void main(String[] args) throws Exception
{

    Server server = new Server(8080);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase(args.length == 2?args[1]:".");
    resource_handler.setWelcomeFiles(new String[]{ "WEB-INF/index.html" });


    System.out.println("serving " + resource_handler.getBaseResource());

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
    server.setHandler(handlers);
    server.start();
    server.join();

}

index.html is

 <html>
<head>
    <title>HTML Generator Sample Page</title>
</head>
<body>
    <h1 style="text-align: center;">
        Agent Management Interface</h1>
    <ol>
        <li>
            Start Platform</li>
        <li>
            Show Agent Status</li>
        <li>
            Create Dummy Agent</li>
        <li>
            Intiate Request Message</li>
        <li>
            Stop agent</li>
        <li>
            Stop Platform</li>
    </ol>
    <p>
        Enter option :</p>
    <p>
        <textarea cols="10" name="myTextBox" rows="1" style="width: 104px; height: 25px;"></textarea></p>
    <p>
        <input name="option_selector" type="submit" value="option_selector" /></p>
</body>

the web.xml file is the usual one with a list of welcome files.
when i run the server and launch
localhost:8080 in the web browser, I am getting a 404 error I am not sure what is it that I need to add to the web.xml file or the referncing of the web.xml file is not correct in the HelloWorld.java main method.

Any hints/suggestions will be helpful
EDIT 1:

I am including the server-api.jar file and the jetty.jar file in the classpath and not making using of the Maven plugin for eclipse.

EDIT2:

2012-05-25 14:40:39.253:DBUG:oejs.AsyncHttpConnection:async request (null null)@17160330 org.eclipse.jetty.server.Request@105d88a
2012-05-25 14:40:39.260:DBUG:oejs.Server:REQUEST / on   org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection@1db05b2@127.0.0.1:8080<->127.0.0.1:55062
2012-05-25 14:40:39.264:DBUG:oejs.Server:RESPONSE /  200
2012-05-25 14:40:39.267:DBUG:oejs.AsyncHttpConnection:async request (null null)@17160330 org.eclipse.jetty.server.Request@105d88a
2012-05-25 14:40:39.272:DBUG:oejs.AsyncHttpConnection:async request (null null)@17160330 org.eclipse.jetty.server.Request@105d88a
2012-05-25 14:40:39.273:DBUG:oejs.Server:REQUEST /jetty-dir.css on org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection@1db05b2@127.0.0.1:8080<->127.0.0.1:55062
2012-05-25 14:40:39.275:DBUG:oejs.Server:RESPONSE /jetty-dir.css  404
  • 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-04T17:03:16+00:00Added an answer on June 4, 2026 at 5:03 pm

    You’ve set your welcome file to WEB-INF/index.html. Items that are located inside the WEB-INF folder are only visible to the servlet container and are not accessible outside of the container.

    This will not work, since index.html is hidden behind WEB-INF. Additionally, when working with WEB-INF, it’s customary to access it from the root of the application, such as /WEB-INF/file.html:

    resource_handler.setWelcomeFiles(new String[]{ "WEB-INF/index.html" });
    

    If you include just the index.html file as a welcome file, and also make sure index.html is in the root of your application, the Jetty Server should be able to find it:

    resource_handler.setWelcomeFiles(new String[]{ "index.html" });
    

    Be sure to restart Jetty after making this change, since the application will need to reload this information.

    Also, when configuring a new Web application on a server, it’s generally a good idea to turn your logging levels all the way up. The server and frameworks typically log at lower levels so they don’t interfere with application logs; however, in this case, you need to see what resources the servlet container is trying to access when you load localhost:8080 in your browser.

    To clarify further, the ResourceHandler.setWelcomeFiles Java method is the same as configuring the server via web.xml in non-embedded Jetty, using the following XML entry:

        <welcome-file-list>
                <welcome-file>index.html</welcome-file>
        </welcome-file-list>
    

    There are some examples and more documentation at the Eclipse Wiki Page on Embedding Jetty, be sure to check them out for more guidance.

    File structure of embedded Jetty 6:

    Here is an example file structure of a copy of embedded Jetty that I have. Note that the index.html is in the root, right next to src:

    build.properties*  index.html*  README.textile*  src/   war/
    build.xml*         licenses/    server/          test/  WEB-INF/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am a newbie on web development, so i have some problems first of
I have to tell you guys first that I'm a newbie of web development
As a newbie in the world of web development, I have a handful of
I am a newbie to Java Web Application development. So far all I have
I'm a python newbie and starting out with using the Bottle web framework on
I'm a relative newbie to web development. I know my HTML and CSS, and
I am newbie in SharePoint 2010 but have experience in ASP.NET (C#) development. I
I am a newbie in web-development and am trying to use Jmeter for doing
I'm a newbie to Java-related web development, and I can't seem to get a
I'm a newbie to javascript (or web development of any sort, really), and having

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.