| // ======================================================================== |
| // Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd. |
| // ======================================================================== |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // and Apache License v2.0 which accompanies this distribution. |
| // |
| // The Eclipse Public License is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // The Apache License v2.0 is available at |
| // http://www.opensource.org/licenses/apache2.0.php |
| // |
| // You may elect to redistribute this code under either of these licenses. |
| // ======================================================================== |
| |
| [[jetty-helloworld]] |
| === Jetty Embedded HelloWorld |
| |
| This section provides a tutorial that shows how you can quickly develop embedded code against the Jetty API. |
| |
| [[downloading-jars]] |
| ==== Downloading the Jars |
| |
| Jetty is decomposed into many jars and dependencies to achieve a minimal footprint by selecting the minimal set of jars. |
| Typically it is best to use something like Maven to manage jars, however this tutorial uses an aggregate Jar that contains all of the Jetty classes in one Jar. |
| You can manually download the aggregate link:http://central.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/{VERSION}/jetty-all-{VERSION}-uber.jar[`jetty-all.jar`] using `curl`) or a browser. |
| |
| ____ |
| [NOTE] |
| The central Maven repository has started to aggressively reject/deny access to the repository from the `wget` command line tool (due to abusive use of the tool by some groups). |
| The administrators of the central maven repository have stated that the recommended command line download tool is now curl. |
| ____ |
| |
| Use curl as follows: |
| |
| [source, screen, subs="{sub-order}"] |
| .... |
| > mkdir Demo |
| > cd Demo |
| > curl -o jetty-all-uber.jar http://central.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/{VERSION}/jetty-all-{VERSION}-uber.jar |
| .... |
| |
| [[writing-helloworld-example]] |
| ==== Writing a HelloWorld Example |
| |
| The link:#embedding[Embedding Jetty] section contains many examples of writing against the Jetty API. |
| This tutorial uses a simple HelloWorld handler with a main method to run the server. |
| You can either link:{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/HelloWorld.java[download] or create in an editor the file `HelloWorld.java` with the following content: |
| |
| [source, java, subs="{sub-order}"] |
| ---- |
| include::{SRCDIR}/examples/embedded/src/main/java/org/eclipse/jetty/embedded/HelloWorld.java[] |
| ---- |
| |
| [[compiling-helloworld-example]] |
| ==== Compiling the HelloWord example |
| |
| The following command compiles the HelloWorld class: |
| |
| [source, screen, subs="{sub-order}"] |
| .... |
| > mkdir classes |
| > javac -d classes -cp jetty-all-uber.jar HelloWorld.java |
| .... |
| |
| [[running-handler-and-server]] |
| ==== Running the Handler and Server |
| |
| The following command runs the HelloWorld example: |
| |
| [source, screen, subs="{sub-order}"] |
| .... |
| > java -cp classes:jetty-all-uber.jar org.eclipse.jetty.embedded.HelloWorld |
| .... |
| |
| You can now point your browser at http://localhost:8080/[http://localhost:8080] to see your hello world page. |
| |
| [[next-steps]] |
| ==== Next Steps |
| |
| To learn more about Jetty, take these next steps: |
| |
| * Follow the examples in link:#embedding-jetty[Embedding Jetty] to better understand the jetty APIs. |
| * Explore the complete link:{JDURL}/[Jetty javadoc] |
| * Consider using link:#maven-and-jetty[Jetty and Maven] to manage your Jars and dependencies. |