Jump to: navigation, search

Difference between revisions of "Jetty/Howto/Using Jetty Runner"

< Jetty‎ | Howto
m (New page: {Jetty Howto | introduction = (required) For a fast and easy way to run your webapp, without having to install and administer a Jetty distro, use the Jetty Runner. The idea of the Jetty R...)
 
Line 1: Line 1:
{Jetty Howto
+
{{Jetty Howto
| introduction = (required)
+
| introduction =  
  
For a fast and easy way to run your webapp, without having to install and administer a Jetty distro, use the Jetty Runner. The idea of the Jetty Runner is extremely simple –run a webapp from the command line using a single Jar and as much default configuration as possible:<br />
+
For a fast and easy way to run your webapp, without having to install and administer a Jetty distro, use the Jetty Runner. The idea of the Jetty Runner is extremely simple–run a webapp from the command line using a single Jar and as much default configuration as possible:<br />
  
 
   java -jar jetty-runner.jar my.war
 
   java -jar jetty-runner.jar my.war
Line 10: Line 10:
 
   java -jar jetty-runner.jar --path /one my1.war --path /two my2 <br />
 
   java -jar jetty-runner.jar --path /one my1.war --path /two my2 <br />
  
Or, for those webapps that need a little more configuration, you can run them via jetty context config files:<br />
+
Or, for those webapps that need a little more configuration, you can run them via jetty context config files:<br />
  
 
   java -jar jetty-runner.jar contexts/my.xml
 
   java -jar jetty-runner.jar contexts/my.xml
  
You can configure the most common elements from the command line, such as the port to start on, and whether to generate a request log or not:<br />
+
You can configure the most common elements from the command line, such as the port to start on, and whether to generate a request log or not:<br />
  
 
  �java --jar jetty-runner.jar --port 9090 --log my/request/log/goes/here my.war
 
  �java --jar jetty-runner.jar --port 9090 --log my/request/log/goes/here my.war
  
You can even configure a JDBC JNDI Resource entry right on the command line. Here's an example to define a Postgres DB available in JNDI at java:comp/env/jdbc/mydatasource:<br />
+
You can even configure a JDBC JNDI Resource entry right on the command line. Here's an example to define a Postgres DB available in JNDI at java:comp/env/jdbc/mydatasource:<br />
  
 
   java -jar jetty-runner.jar \<br />  --lib ~/src/tools/derby/ --lib ~/src/tools/atomikos  \<br />  --jdbc org.apache.derby.jdbc.EmbeddedXADataSource "databaseName=testdb;createDatabase=create" "jdbc/mydatasource" \<br />  my.war
 
   java -jar jetty-runner.jar \<br />  --lib ~/src/tools/derby/ --lib ~/src/tools/atomikos  \<br />  --jdbc org.apache.derby.jdbc.EmbeddedXADataSource "databaseName=testdb;createDatabase=create" "jdbc/mydatasource" \<br />  my.war
  
The syntax of the --jdbc argument is:<br />
+
The syntax of the --jdbc argument is:<br />
  
 
   --jdbc <classname of Driver or XADataSource> <db properties> <jndiname>
 
   --jdbc <classname of Driver or XADataSource> <db properties> <jndiname>
  
You must also tell Jetty where to find your database driver and Atomikos, which we use to provide a transaction manager and wrap XA and non-XA Resources into a DataSource you can access from your webapp.<br /><br /> Notice the --lib argument, which is one way to tell Jetty about extra jars you want to put onto the container's classpath. You can also use:<br />
+
You must also tell Jetty where to find your database driver and Atomikos, which we use to provide a transaction manager and wrap XA and non-XA Resources into a DataSource you can access from your webapp.<br /><br /> Notice the --lib argument, which is one way to tell Jetty about extra jars you want to put onto the container's classpath. You can also use:<br />
  
 
   --jar <filename><br /> --classes <dir><br />
 
   --jar <filename><br /> --classes <dir><br />

Revision as of 16:10, 3 October 2011



Introduction

For a fast and easy way to run your webapp, without having to install and administer a Jetty distro, use the Jetty Runner. The idea of the Jetty Runner is extremely simple–run a webapp from the command line using a single Jar and as much default configuration as possible:

  java -jar jetty-runner.jar my.war

Jetty starts on port 8080 and deploys the my.war webapp. You can also deploy multiple webapps–either packed or unpacked WARs–from the command line. In this example, my.war is available at http://host:8080/one and the my2 webapp is available at http://host:8080/two:

  java -jar jetty-runner.jar --path /one my1.war --path /two my2 

Or, for those webapps that need a little more configuration, you can run them via jetty context config files:

  java -jar jetty-runner.jar contexts/my.xml

You can configure the most common elements from the command line, such as the port to start on, and whether to generate a request log or not:

�java --jar jetty-runner.jar --port 9090 --log my/request/log/goes/here my.war

You can even configure a JDBC JNDI Resource entry right on the command line. Here's an example to define a Postgres DB available in JNDI at java:comp/env/jdbc/mydatasource:

 java -jar jetty-runner.jar \
--lib ~/src/tools/derby/ --lib ~/src/tools/atomikos \
--jdbc org.apache.derby.jdbc.EmbeddedXADataSource "databaseName=testdb;createDatabase=create" "jdbc/mydatasource" \
my.war

The syntax of the --jdbc argument is:

 --jdbc <classname of Driver or XADataSource> <db properties> <jndiname>

You must also tell Jetty where to find your database driver and Atomikos, which we use to provide a transaction manager and wrap XA and non-XA Resources into a DataSource you can access from your webapp.

Notice the --lib argument, which is one way to tell Jetty about extra jars you want to put onto the container's classpath. You can also use:

 --jar <filename>
--classes <dir>

In addition, you can get full configuration control using a jetty.xml configuration file:

 java -jar jetty-runner.jar --config my/jetty.xml my.war
To see all your options, enter:
 java -jar jetty-runner.jar --help

How to Get the jetty-runner.jar

You can download the jetty-runner jar from the main maven repo at: http://repo2.maven.org/maven2/org/mortbay/jetty/jetty-runner/