Jetty home system property is not set

user1226868 picture user1226868 · May 22, 2013 · Viewed 12.3k times · Source

I'm trying to use the system property in my jetty config as the following:

<SystemProperty name="jetty.home" default="" />/etc/jetty7/context

But the jetty.home always returns empty. How can i set this variable and point it to where?

I need this for an context path.

My jetty home folder is D:\Developer Tools\jetty-6.1.26. Does it need to point to this folder? If so, how can i do this? Do i need to use Windows global variables?

I'm using the org.eclipse.jetty.xml.XmlConfiguration class from org.mortbay.jetty.

Answer

Joakim Erdfelt picture Joakim Erdfelt · May 22, 2013

jetty.home is set by Jetty's start mechanism.

You are using Jetty 6.1.26 (note: Jetty 6.x has been deprecated and end of life'd back in 2010)

While I don't know how Jetty 6 worked, I do know how Jetty 7/8/9 work in this respect.

Update: Aug 2019: Jetty 9.4.x is the current stable & actively supported version mainline of Jetty.

The Jetty start mechanism (module: /jetty-start/. aka start.jar) would establish the jetty.home property based on a set of rules in the start.config (a file present in the start.jar) and then use the org.eclipse.jetty.xml.XmlConfiguration class (also defined in the start.config) to establish a set of properties in the XmlConfiguration object, then load the XML files declared on the command line and start.ini.

Problem #1: Mixed Jetty Versions

You have a mix of Jetty versions, that can work, but not across Jetty 6 (as seen in your declared jetty home folder of D:\Developer Tools\jetty-6.1.26) and Jetty 7 (as seen in your /etc/jetty7/context declaration). They are 100% incompatible.

Problem #2: Bad XML Syntax Use

Your XML syntax for working with paths is wrong.

Your Syntax

<Set name="monitoredDir">
    <SystemProperty name="jetty.home" default="" />/etc/jetty7/context
</Set>
  1. It is a mix of relative and absolute paths and will not work.
  2. You must always declare a default value on <SystemProperty> use when working with paths. (empty default is invalid)

Correct Syntax for Relative Paths

<Set name="monitoredDir">
    <SystemProperty name="jetty.home" default="." />etc/jetty7/context
</Set>

If your jetty.home is D:\Developer Tools\jetty-distribution-7.6.11.v20130520, then this will point to D:\Developer Tools\jetty-distribution-7.6.11.v20130520\etc\jetty7\context

If you don't declare jetty.home before using XmlConfiguration then the default value will be used, the "." it will be translated as whatever your current working directory is (also known as System.getProperty("user.dir")) plus the hardcoded relative path you specified. If user.dir is D:\Code\MyProject, then the result would be D:\Code\MyProject\etc\jetty7\context

Correct Syntax for Absolute Paths

<Set name="monitoredDir">/etc/jetty7/context</Set>

This syntax could care less about jetty.home and the result will always be /etc/jetty7/context on unix and (highly likely to be) C:\etc\jetty7\context on windows.