Jetty - set system property

Bostone picture Bostone · Oct 9, 2010 · Viewed 26.8k times · Source

I run webapp on Jetty. The configuration for the app come from file that lives on the same server where Jetty is running. Inside the app I rely on the system property to obtain path to the file so I can parse it. E.g.

final String loc = System.getProperty(FACTORY);

Now I can start jetty with D switch to provide $FACTORY on the command line but I rather put it in jetty.xml if I can. I know there is <SystemProperty /> tag but that seems to just provide system value that already exists for the <Set/> tag. Can someone give me example how this can be achieved? (If it can be achieved)

Answer

thoredge picture thoredge · Jan 19, 2011

For the record, if you really need to do this through system properties (I did) you can do this to append for example -Drun.mode=staging to the system properties:

<Call class="java.lang.System" name="setProperties">
  <Arg>
    <New class="java.util.Properties">
      <Call name="putAll">
        <Arg><Call class="java.lang.System" name="getProperties"/></Arg>
      </Call>
      <Call name="setProperty">
        <Arg>run.mode</Arg>
        <Arg>staging</Arg>
      </Call>
    </New>
  </Arg>
</Call>

... and yes you can probably can program your application through this ;-)