Jetty 9.3 Quickstart

Steps to get Jetty up and running:

1) Download the zip from http://download.eclipse.org/jetty

2) Unzip to a location (e.g. /opt/jetty)

3) Define environment variables
export JETTY_HOME=/opt/jetty
export JETTY_BASE=/appl/xxx
export TMPDIR=/appl/xxx/temp

4) Add modules (list of modules can be seen in $JETTY_HOME/modules or –list-modules)
java -jar $JETTY_HOME/start.jar –add-to-startd=http,webapp,deploy,jsp

5) Create a test application and put into $JETTY_BASE/webapps
mkdir -p $JETTY_BASE/webapps/ROOT/WEB-INF
echo “Hello World!” >$JETTY_BASE/webapps/ROOT/index.jsp
echo <<!
<?xml version=’1.0′ encoding=’UTF-8′?>
<web-app xmlns=”http://java.sun.com/xml/ns/javaee&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; version=”3.0″>
<display-name>TestApp</display-name>
</web-app>
!
>$JETTY_BASE/webapps/ROOT/WEB-INF/web.xml

6) Start Jetty
java -jar $JETTY_HOME/start.jar

7) If everything goes well, can see the application from URL
http://servername:8080

 

Further configurations:

1) Change the listening port and interface in $JETTY_BASE/start.d/http.ini
## Connector host/address to bind to
jetty.http.host=x.x.x.x

## Connector port to listen on
jetty.http.port=8280

2) Add in https module
java -jar $JETTY_HOME/start.jar –add-to-startd=https
cd $JETTY_BASE/etc
keytool -keystore keystore -alias jetty -genkey -keyalg RSA -sigalg SHA256withRSA
Enter keystore password: changeit
What is your first and last name?
[Unknown]: myserver.mydomain.com
What is the name of your organizational unit?
[Unknown]: MyOrgUnit
What is the name of your organization?
[Unknown]: MyOrg
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=myserver.mydomain.com, OU=MyOrgUnit, O=MyOrgUnit,
L=Unknown, ST=Unknown, C=Unknown correct?
[no]: yes

Enter key password for <jetty>
(RETURN if same as keystore password):

Change $JETTY_BASE/start.d/ssl.ini
## Connector host/address to bind to
jetty.ssl.host=x.x.x.x

## Connector port to listen on
jetty.ssl.port=8543

## Keystore password
jetty.sslContext.keyStorePassword=OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0

## KeyManager password
jetty.sslContext.keyManagerPassword=OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0

Note: The obfuscated password can be generated using org.eclipse.jetty.util.security.Password

java -cp $JETTY_HOME/lib/jetty-util-9.3.14.v20161028.jar org.eclipse.jetty.util.security.Password dummy changeit

2016-11-25 16:24:41.933:INFO::main: Logging initialized @186ms
changeit
OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0
MD5:b91cd1a54781790beaa2baf741fa6789
CRYPT:dujr7UJ/qmJIQ

3) Add in logging module

4) Set up auto-start after Linux reboot
(init.d way)
cp $JETTY_HOME/bin/jetty.sh /etc/init.d/jetty
echo “JETTY_HOME=/opt/jetty” > /etc/default/jetty
echo “JETTY_BASE=/appl/xxx” >> /etc/default/jetty
echo “TMPDIR=/appl/xxx/temp” >> /etc/default/jetty

(systemd way)
Create file /etc/systemd/system/jetty.service

[Unit]
Description=Jetty process
After=multi-user.target

[Service]
Type=simple
User=jetty
Group=jetty
ExecStartPre=/bin/bash –login -c ‘env > /tmp/.jetty-environment-file’
ExecStart=java $JAVA_OPTIONS -jar $JETTY_HOME/start.jar STOP.HOST=localhost STOP.PORT=8115 STOP.KEY=SHUTDOWN STOP.WAIT=30
ExecStop=java -jar $JETTY_HOME/start.jar –stop STOP.HOST=localhost STOP.PORT=8115 STOP.KEY=SHUTDOWN STOP.WAIT=30
EnvironmentFile=-/tmp/.jetty-environment-file
Restart=no

[Install]
WantedBy=multi-user.target

systemctl enable jetty
systemctl daemon-reload

systemctl start jetty
systemctl status jetty -l

systemctl stop jetty
systemctl status jetty -l

 

References:

http://www.eclipse.org/jetty/documentation/current/index.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s