Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is jetty /context/text.xml?

I am following this tutorial and I am stuck with Jetty configuration. This says that

Now, change directory to your Jetty install, and to get a working set of default configuration options, just copy the file contexts/test.xml (which comes packaged with Jetty by default) to a new file:

$ cp contexts/test.xml contexts/web_test.xml

But my jetty install has no /context directory:

as-MacBook-Air:jetty.home a$ ls
README.TXT
VERSION.txt
bin
demo-base
etc
lib
license-eplv10-aslv20.html
logs
modules
notice.html
resources
start.d
start.ini
start.jar
webapps

What am I missing? Where is jetty text.xml file?

like image 632
Zeynel Avatar asked Dec 19 '22 20:12

Zeynel


1 Answers

Documentation Link: Configuring a Specific Web Application Deployment

A "context xml" is any XML file that :

  1. Follows the Jetty IoC XML syntax
  2. Configures a org.eclipse.jetty.webapp.WebAppContext
  3. And is in a directory that your deployer recognizes

For #2 (Configuring a WebAppContext), an example for Jetty 9 would be

<?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">/myapp</Set>
  <Set name="war"><Property name="jetty.webapps" default="."/>/myapp.war</Set>
  <Set name="extractWAR">true</Set>
</Configure>

For #3, the deployer directory, that is determined by your own setup and configuration.

See etc/jetty-deploy.xml and look for what your monitoredDirName is.

  • For Jetty 9.1+, that's ${jetty.base}/webapps/
  • For Jetty 8 that's ${jetty.home}/contexts/ see (etc/jetty-contexts.xml)
  • For Jetty 7 that's ${jetty.home}/contexts/ see (etc/jetty-contexts.xml)

Jetty 7 and Jetty 8 had a quirk in the deployers that was poorly understood, you could deploy a webapp as a WAR via the webapp deployer, or as Context via the context deployer, and if you had both deployers, your webapp would be deployed twice. (confusing endless numbers of people).

With Jetty 9, the 2 deployer techniques were merged to make them aware of each other and prevent duplicate webapp deployment.

The logic for deployment in Jetty 9 is as follows:

The webapps directory (aka monitoredDirName) is scanned by the WebAppProvider.

This provider scans one or more directories (typically "webapps") for contexts to deploy, which may be:

  • A standard WAR file (must end in ".war")
  • A directory containing an expanded WAR file
  • A directory containing static content
  • An XML descriptor Jetty IoC XML Syntax that configures a ContextHandler or WebAppContext instance

To avoid double deployments and allow flexibility of the content of the scanned directories, the provider implements some heuristics to ignore some files found in the scans:

  • Hidden files (starting with ".") are ignored
  • Directories with names ending in ".d" are ignored
  • If a directory and a WAR file exist ( eg foo/ and foo.war) then the directory is assumed to be the unpacked WAR and only the WAR is deployed (which may reused the unpacked directory)
  • If a directory and a matching XML file exist ( eg foo/ and foo.xml) then the directory is assumed to be an unpacked WAR and only the XML is deployed (which may used the directory in it's configuration)
  • If a WAR file and a matching XML exist (eg foo.war and foo.xml) then the WAR is assumed to be configured by the XML and only the XML is deployed.
like image 133
Joakim Erdfelt Avatar answered Dec 31 '22 15:12

Joakim Erdfelt