- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
Basic administration
This part of the Jetty tutorial covers basic administration and configuration of Jetty.
First, we need to have set the basic Jetty environment variables. The environment variables are set in the system-wide /etc/environment
> file or user's .profile
or .bashrc
(for Bash shell) files.
$ echo $JETTY_HOME /home/janbodnar/bin/jetty $ echo $JETTY_BASE /home/janbodnar/prog/jetty/my-base
We can now refer to Jetty home and Jetty base using these two variables in our commands.
Jetty base
Jetty base is our customised Jetty environment, where we place our own configuration files, logs, and where we have the deployment directory. The deployment directory's default name is webapps
.
To create a Jetty base, we create a new directory and enable necessary modules with the start.jar
command. Jetty is then started from this directory. Alternatively, we specify jetty.base
property as a command line option.
$ cd $JETTY_BASE $ java -jar $JETTY_HOME/start.jar
These two commands start Jetty from the Jetty base directory. Jetty automatically loads configuration files located in the directory—the start.ini
file, and optionally, files located in resources
, modules
, and etc
subdirectories.
$ java -jar $JETTY_HOME/start.jar jetty.base=$JETTY_BASE
If we are not located in the Jetty base directory, we can enable Jetty base environment by specifying the jetty.base
command line option.
The start.jar command
The start.jar
tool, located in Jetty home, is used to start Jetty, provide information, and perform some configuration settings.
$ java -jar $JETTY_HOME/start.jar --help
The --help
option prints the current list of command line options and some basic usage help.
$ ls -l $JETTY_BASE total 0 $ cd $JETTY_BASE $ java -jar $JETTY_HOME/start.jar --add-to-start=deploy,http INFO: deploy initialised in ${jetty.base}/start.ini (appended) MKDIR: ${jetty.base}/webapps INFO: webapp initialised transitively INFO: servlet initialised transitively INFO: security initialised transitively INFO: server initialised transitively INFO: http initialised in ${jetty.base}/start.ini (appended) INFO: server initialised transitively $ ls start.ini webapps
Jetty is a highly modular system. The --add-to-start
option enables Jetty modules by appending them to the ${jetty.base}/start.ini file. The command enabled the deploy and HTTP modules, and also modules on which they depend. The command also created the start.ini
file and the webapps deployment directory. The start.ini
file is loaded by Jetty at startup time.
$ java -jar $JETTY_HOME/start.jar --list-modules ... Jetty Active Module Tree: ------------------------- + Module: server [enabled] + Module: http [enabled] + Module: security [enabled] + Module: servlet [enabled] + Module: webapp [enabled] + Module: deploy [enabled] ...
Here we see a partial output of the --list-modules
option. It lists all available Jetty modules—active and inactive.
$ java -jar $JETTY_HOME/start.jar --list-config ... Jetty Active XMLs: ------------------ ${jetty.home}/etc/jetty.xml ${jetty.home}/etc/jetty-http.xml ${jetty.home}/etc/jetty-deploy.xml
The --list-config
option lists configuration settings including Java and Jetty environments, JVM arguments, properties, Server classpath, and XML configuration files. The partial output shows active XML configuration files loaded by Jetty.
The deployment directory
The deployment directory is a directory where we deploy our WAR files. The default name of the directory is webapps. The directory is located in Jetty home and Jetty base directories.
... <Set name="monitoredDirName"><Property name="jetty.base" default="." />/ <Property name="jetty.deploy.monitoredDirName" default="webapps"/></Set> ...
The default deployment directory's name is specified in the $JETTY_HOME/etc/jetty-deploy.xml
file.
$ java -jar $JETTY_HOME/start.jar jetty.deploy.monitoredDirName=webapps2
We can set the property value on the command line.
$ cat start.ini # # Initialize module deploy # --module=deploy ## DeployManager configuration # Monitored Directory name (relative to jetty.base) jetty.deploy.monitoredDirName=webapps3
Another possibility is to set the deployment directory name inside the start.ini
file's deploy module section.
$ cat myjetty.properties jetty.deploy.monitoredDirName=webapps4 $ java -jar $JETTY_HOME/start.jar myjetty.properties
The deployment directory can be set in a properties file, which is passed to the start.jar
tool.
We have shown four places where the deployment directory can be set. If there is a conflict, the value is taken from the option with the highest order. The order is the following: ( a
) the Java property file; ( b
) the command line option; ( c
) the Jetty base start.ini
file; and ( d
) the jetty-deploy.xml
file located in Java home's etc
directory.
Jetty XML files
Jetty can be configured with XML configuration files. The jetty.xml
is a default Jetty configuration file. It configures the server class, the ThreadPool, the connectors, the handler structure, the deployment manager, the login service, and the request log. The jetty-web.xml
is a Jetty configuration file that can be bundled with a specific web application. The jetty-env.xml
is an optional Jetty configuration file that arranges JNDI resources for an individual web application. The webdefault.xml
configuration file is applied to a web application before its own web.xml
file. It is used to save a web application from having to define a lot of house-keeping and container-specific elements in their own web.xml
files. The override-web.xml
is a web application configuration file that is applied after the application's own web.xml
file.
Application context
A context path is a part of a URL path that is used to select the web application to which an incoming request is routed. The context path can be set with a method call (in embedded Jetty), derived from the name of the WAR file, specified in the deployer XML file or in the jetty-web.xml
. The next example will use the jetty-web.xml
file to set the application's context path. The file is located inside the WEB-INF
directory.
$ tree . ├── build.xml └── src ├── com │ └── zetcode └── web ├── index.html └── WEB-INF └── jetty-web.xml 5 directories, 3 files
We list the directory structure of the project.
index.html
<!DOCTYPE html> <html> <body> Simple page. </body> </html>
This is a simple HTML file.
jetty-web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/myapp</Set> <Get class="org.eclipse.jetty.util.log.Log" name="rootLogger"> <Call name="warn"><Arg>Web application is deployed</Arg></Call> </Get> </Configure>
In the jetty-web.xml
file, we set the context to /myapp
. We also log a message upon deployment.
build.xml
<?xml version="1.0" encoding="UTF-8"?> <project name="AppContext" default="archive"> <property name="name" value="appcontext"/> <property environment="env"/> <property name="src.dir" value="src"/> <property name="web.dir" value="${src.dir}/web"/> <property name="dist.dir" location="dist"/> <property name="deploy.path" location="${env.JETTY_BASE}/webapps"/> <target name="init"> <mkdir dir="${dist.dir}"/> </target> <target name="archive"> <war destfile="${dist.dir}/${name}.war" needxmlfile="false"> <fileset dir="${web.dir}"/> </war> <echo>Archive created</echo> </target> <target name="clean" depends="init"> <delete dir="${dist.dir}"/> <echo>Cleaning completed</echo> </target> <target name="deploy" depends="archive"> <copy file="${dist.dir}/${name}.war" overwrite="true" todir="${deploy.path}"/> <echo>Archive deployed</echo> </target> </project>
This is Ant build file.
<property environment="env"/>
The environment atttribute sets the prefix to use OS environment variables.
<property name="deploy.path" location="${env.JETTY_BASE}/webapps"/>
We use the JETTY_BASE
environment variable to define the deployment path.
$ curl localhost:8080/myapp/ <!DOCTYPE html> <html> <body> Simple page. </body> </html>
We connect to the web application using the selected context path. If we have not specified the context file explicitly, it would be derived from the WAR file name, which is given in the third line of the build.xml
file.
Deployment descriptor
Deployment descriptors are XML files used to deploy web applications. The name of the XML file must match the name of the WAR file. If both WAR file and XML file are present in the deployment directory, the XML file is used for the deployment.
We use the previous example code.
appcontext.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/myapp2</Set> <Set name="war">/home/janbodnar/prog/jetty/appcontext/dist/appcontext.war</Set> </Configure>
Inside the deployment descriptor, we set the context path and specify the WAR file using an absolute location path.
jetty-web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <!-- <Set name="contextPath">/myapp</Set> --> <Get class="org.eclipse.jetty.util.log.Log" name="rootLogger"> <Call name="warn"><Arg>Web application is deployed</Arg></Call> </Get> </Configure>
The jetty-web.xml
is called after all other configuration has been applied to the web application. Therefore, we comment the line specifying the context path.
$ curl localhost:8080/myapp2/ <!DOCTYPE html> <html> <body> Simple page. </body> </html>
The modified context path works.
In this chapter, we have showed some basic administration of the Jetty server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论