//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

[[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 link:#jetty-maven-helloworld[Maven] to manage jars, however this tutorial uses an aggregate Jar that contains all of the required Jetty classes in one Jar.
You can manually download the aggregate link:https://repo1.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.
____

____
[IMPORTANT]
The `jetty-all` jar referenced in this section is for example purposes only and should not be used outside of this context.
Please consider using link:#jetty-maven-helloworld[Maven] to manage your project dependencies.
____

Use curl as follows:

[source, screen, subs="{sub-order}"]
....
> mkdir Demo
> cd Demo
> curl -o jetty-all-uber.jar https://repo1.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:{GITBROWSEURL}/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.
