alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Jetty example source code file (FromXmlConfiguration.java)

This example Jetty source code file (FromXmlConfiguration.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Jetty tags/keywords

arg, call, configure, configure, fromxmlconfiguration, new, server, server, set, set, string, systemproperty, xmlconfiguration, xmlconfiguration

The Jetty FromXmlConfiguration.java source code

package org.mortbay.jetty.example;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.xml.XmlConfiguration;

public class FromXmlConfiguration
{
    public static void main(String[] args)
        throws Exception
    {
        String server_config=
            "<Configure id=\"Server\" class=\"org.mortbay.jetty.Server\">\n"+
            "  <Call name=\"addConnector\">\n" +
            "    <Arg>\n" +
            "      <New class=\"org.mortbay.jetty.nio.SelectChannelConnector\">\n" +
            "        <Set name=\"port\">\n" +
            "      </New>\n" +
            "    </Arg>\n"+
            "  </Call>\n"+
            "</Configure>\n";
   
        String context_config=
            "<Configure id=\"Server\" class=\"org.mortbay.jetty.servlet.Context\">\n"+
            "  <Set name=\"contextPath\">/\n"+
            "  <Set name=\"resourceBase\">\n"+
            "  <Call name=\"addServlet\">org.mortbay.jetty.servlet.DefaultServlet/\n"+
            "</Configure>\n";
        
        // Apply configuration to an existing object
        Server server = new Server();
        XmlConfiguration configuration = new XmlConfiguration(server_config); 
        configuration.configure(server);
        
        // configuration creates new object
        configuration = new XmlConfiguration(context_config); 
        ContextHandler context = (ContextHandler)configuration.configure();
        
        server.setHandler(context);
        server.start();
    }
}

Other Jetty examples (source code examples)

Here is a short list of links related to this Jetty FromXmlConfiguration.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.