Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Jetty/Feature/Start.jar"

< Jetty‎ | Feature
(New page: {{Jetty Feature |introduction= xxx |body= yyy }})
 
Line 1: Line 1:
 
{{Jetty Feature
 
{{Jetty Feature
|introduction=
+
|introduction=Jetty is just a java program that can be run like any other java program once a classpath has been setup. For example, the SimplestServer from the [[Jetty/Tutorial/Embedding_Jetty|Embedding Jetty]] could be run as follows:
xxx
+
<source lang="bash">
 +
java -cp $JETTY_CLASSPATH org.eclipse.jetty.embedded.SimplestServer
 +
</source>
 +
 
 +
Similarly if you configure your server with [[Jetty/Reference/jetty.xml_syntax|jetty.xml]] rather than a java main, then the server can be run with:
 +
 
 +
<source lang="bash">
 +
java -cp $JETTY_CLASSPATH org.eclipse.jetty.xml.XmlConfiguration etc/jetty.xml
 +
</source>
 +
 
 +
The difficult part of both these examples is knowing what must be on the JETTY_CLASSPATH.  The jetty server comes in over 46 jars, so working out exactly which are needed can be difficult.  If you develop with maven, these jar dependencies can be managed for you, but you still need to setup a classpath when running from the command line.
 +
 
 +
The start.jar mechanism is an executable jar file that will build a class path and then execute your main program. It is a generic mechanism that can be used with any java program and it's behaviour is controlled by a [http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config start.config] file.  The standard start.jar comes with a [http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config start.config] file for jetty, so that you can start jetty with:
 +
 
 +
<source lang="bash">
 +
java -jar start.jar
 +
</source>
 +
 
 
|body=
 
|body=
yyy
+
 
 +
=== Building the environment ===
 +
 
 +
The start.jar builds and environment of java system properties and start properties that are used to parameterize the start mechanism and the execution of the program. In a start.config, the string ${name} is expanded to a start property and $(name) is expanded to either a start property or a system property. 
 +
 
 +
The main property set by the default start.config is jetty.home, which is assumed to be the directory in which start.jar is deployed.  If the jetty.home is not set with a -Djetty.home then ".", ".." and some well known directories are searched for start.jar
 +
 
 +
The $(version) property is also determined by examining the manifest of the start.jar.
 +
 
 +
 
 +
=== Building the classpath ===
 +
 
 +
The default start.config assumes that all the jetty jars will be in a directory tree under ${jetty.home}/lib  The following jars are put on all classpaths built by the default start.config:
 +
<source lang="text">
 +
$(jetty.home)/lib/jetty-util-$(version).jar
 +
$(jetty.home)/lib/jetty-io-$(version).jar
 +
</source>
 +
 
 +
If no OPTION are specified, then the following entries are also added by default:
 +
<source lang="text">
 +
$(jetty.home)/resources/
 +
$(jetty.home)/lib/jetty-xml-$(version).jar 
 +
$(jetty.home)/lib/servlet-api-2.5.jar   
 +
$(jetty.home)/lib/jetty-http-$(version).jar 
 +
$(jetty.home)/lib/jetty-continuation-$(version).jar
 +
$(jetty.home)/lib/jetty-server-$(version).jar
 +
$(jetty.home)/lib/jetty-security-$(version).jar
 +
$(jetty.home)/lib/jetty-servlet-$(version).jar 
 +
$(jetty.home)/lib/jetty-webapp-$(version).jar 
 +
$(jetty.home)/lib/jetty-deploy-$(version).jar 
 +
$(jetty.home)/lib/jetty-servlets-$(version).jar
 +
$(jetty.home)/lib/ext/*.jar
 +
</source>
 +
This is sufficient to run most standard web applications.
 +
 
 +
If the system property ${path} is defined, then it is treated as a classpath string and prepended to the generated classpath. If the system property ${lib} is defined, then it is treated as a directory of jars and all jars discovered are prepended to the generated classpath.
 +
 
 +
===== OPTIONS =====
 +
Options may be specified to the start.jar to change the default jars added to the classpath:
 +
<source lang="bash">
 +
java -jar start.jar OPTIONS=Server,jmx,ajp,setuid
 +
</source>
 +
 
 +
The available options may be listed with
 +
<source lang="bash">
 +
java -jar start.jar --help
 +
</source>
 +
 
 +
If an option is specified, then the default jars listed above are not added to the classpath.  There are three types of options available:
 +
* <b>Convenience Options</b> - By convention, options starting with a capital letter are convenience options that include many other options. For example the "Server" option includes all the options commonly needed to run a server: xml,server,security,servlet,webapp,deploy and servlets options; while the option "server" contains just the jars for the core HTTP server.  "All" is the other convenience option.
 +
* <b>Known module options</b> - The main known jetty modules each have an option predefined to select their required jars. Known options include xml,server, security, servlet, webapp, deploy, serlvets, rewrite, jmx, ajp, jndi, annotations, setuid, policy and client.
 +
* <b>Discovered options</b> - Directories within ${jetty.home}/lib can be discovered as options. The "lib/ext", "lib/jsp" and "lib/jta" are directories that may be discovered as an options
 +
 
 +
=== Building the arguments ===
 +
 
 +
=== Running the main ===
 +
 
 +
 
 +
 
 
}}
 
}}

Revision as of 23:35, 15 September 2009



Introduction

Jetty is just a java program that can be run like any other java program once a classpath has been setup. For example, the SimplestServer from the Embedding Jetty could be run as follows:

java -cp $JETTY_CLASSPATH org.eclipse.jetty.embedded.SimplestServer

Similarly if you configure your server with jetty.xml rather than a java main, then the server can be run with:

java -cp $JETTY_CLASSPATH org.eclipse.jetty.xml.XmlConfiguration etc/jetty.xml

The difficult part of both these examples is knowing what must be on the JETTY_CLASSPATH. The jetty server comes in over 46 jars, so working out exactly which are needed can be difficult. If you develop with maven, these jar dependencies can be managed for you, but you still need to setup a classpath when running from the command line.

The start.jar mechanism is an executable jar file that will build a class path and then execute your main program. It is a generic mechanism that can be used with any java program and it's behaviour is controlled by a start.config file. The standard start.jar comes with a start.config file for jetty, so that you can start jetty with:

java -jar start.jar

Feature

Building the environment

The start.jar builds and environment of java system properties and start properties that are used to parameterize the start mechanism and the execution of the program. In a start.config, the string ${name} is expanded to a start property and $(name) is expanded to either a start property or a system property.

The main property set by the default start.config is jetty.home, which is assumed to be the directory in which start.jar is deployed. If the jetty.home is not set with a -Djetty.home then ".", ".." and some well known directories are searched for start.jar

The $(version) property is also determined by examining the manifest of the start.jar.


Building the classpath

The default start.config assumes that all the jetty jars will be in a directory tree under ${jetty.home}/lib The following jars are put on all classpaths built by the default start.config:

 
$(jetty.home)/lib/jetty-util-$(version).jar
$(jetty.home)/lib/jetty-io-$(version).jar

If no OPTION are specified, then the following entries are also added by default:

 
$(jetty.home)/resources/
$(jetty.home)/lib/jetty-xml-$(version).jar  
$(jetty.home)/lib/servlet-api-2.5.jar    
$(jetty.home)/lib/jetty-http-$(version).jar  
$(jetty.home)/lib/jetty-continuation-$(version).jar 
$(jetty.home)/lib/jetty-server-$(version).jar 
$(jetty.home)/lib/jetty-security-$(version).jar 
$(jetty.home)/lib/jetty-servlet-$(version).jar   
$(jetty.home)/lib/jetty-webapp-$(version).jar   
$(jetty.home)/lib/jetty-deploy-$(version).jar  
$(jetty.home)/lib/jetty-servlets-$(version).jar 
$(jetty.home)/lib/ext/*.jar

This is sufficient to run most standard web applications.

If the system property ${path} is defined, then it is treated as a classpath string and prepended to the generated classpath. If the system property ${lib} is defined, then it is treated as a directory of jars and all jars discovered are prepended to the generated classpath.

OPTIONS

Options may be specified to the start.jar to change the default jars added to the classpath:

java -jar start.jar OPTIONS=Server,jmx,ajp,setuid

The available options may be listed with

java -jar start.jar --help

If an option is specified, then the default jars listed above are not added to the classpath. There are three types of options available:

  • Convenience Options - By convention, options starting with a capital letter are convenience options that include many other options. For example the "Server" option includes all the options commonly needed to run a server: xml,server,security,servlet,webapp,deploy and servlets options; while the option "server" contains just the jars for the core HTTP server. "All" is the other convenience option.
  • Known module options - The main known jetty modules each have an option predefined to select their required jars. Known options include xml,server, security, servlet, webapp, deploy, serlvets, rewrite, jmx, ajp, jndi, annotations, setuid, policy and client.
  • Discovered options - Directories within ${jetty.home}/lib can be discovered as options. The "lib/ext", "lib/jsp" and "lib/jta" are directories that may be discovered as an options

Building the arguments

Running the main

Copyright © Eclipse Foundation, Inc. All Rights Reserved.