0

I have a jetty 9 installed on CentOS in /srv/jetty, and I have a webapp deployed inside jetty. When I start jetty with java -jar start.jar & then inside the web application I can do this:

File base = new File(".");
System.out.println("Base Dir: " + base.getAbsolutePath());

And it returns me the correct directory of the jetty installation.

But then I add jetty as a linux service, to run with a user called jetty, and start with service jetty start then calling the above code, will allways give me back the home directory of the user, who is running jetty in this case /home/jetty/ or if I run as root then /root/

How can I set up jetty to find the correct directory? I tried with jetty.home in the config files, but nothing seems to work.

user2687307
  • 13
  • 1
  • 1
  • 5

2 Answers2

1

You have a few things to worry about.

The noteworthy paths for a WebApp on Jetty:

  • ServletContext Real Path
  • Jetty Home
  • Jetty Base (starting in Jetty 9.1)

ServletContext Real Path

All WebApps that are deployed and started, will occupy either a work directory, or a temp directory (on the whim of the container). The servlet spec mandates that this path should be discoverable via the ServletContext for that webapp. You can find out where your WebApp is, by calling ServletContext.getRealPath("/")

See my prior answer for 5 different ways you can configure this work/temp directory: https://stackoverflow.com/a/19232771/775715

Jetty Home

By default, all Jetty Distribution instances will have a System Property called jetty.home that will be the path to the Jetty Home location on disk. This is to be assumed to be where the Jetty Binaries and Distribution configurations are found.

Jetty Base

Starting in Jetty 9.1, there is also a mandatory System Property called jetty.base that is where your specific instance of jetty's configuration + libraries + webapps are housed. This is often a different directory than jetty.home.

This separation of binaries vs configuration is a core concept of Jetty 9.1, adopting a clear separation will making upgrading the Jetty binaries easy.

See http://www.eclipse.org/jetty/documentation/current/startup-base-and-home.html

Community
  • 1
  • 1
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
0

I thing I have found the easy answer:
usermod -m -d /srv/jetty jetty
As it was advised in many places on the internet I created a user jetty to run the jetty service. So whatever I did -even if I set JETTY_LOGS- the log files allways ended up in the users home directory. By modifying the jetty users home directory the File(".") and the logs all end up where I wanted to

user2687307
  • 13
  • 1
  • 1
  • 5