Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Jetty: How to change startup temp directory

I'm trying to deploy a vaadin application to jetty.

But when I run jetty using start.jar, it starts to a subfolder of

C:UsersUSERNAMEAppDataLocalTempjetty-0.0.0.0-8080-Application.war-....

Although I've put it into C:Program FilesMyApp, it always runs there - including the files it saves.

How do I tell jetty to start right where it resides, and have all files relatively to this base?

I'm on Windows 7, we're talking about the most recent, standalone jetty package.

Any idea is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Jetty needs a working directory.

Its search order for finding a work directory is as follows:

  1. If the WebAppContext has a temp directory specified, use it.
  2. If the ServletContext has the javax.servlet.context.tempdir attribute set, and if directory exists, use it.
  3. If a ${jetty.base}/work directory exists, use it (only valid for Jetty 9.1+)
  4. If a ${jetty.home}/work directory exists, use it.
    • Note: starting with Jetty 9.1 this test is now ${jetty.base}/work
  5. If a ServletContext has the org.eclipse.jetty.webapp.basetempdir attribute set, and if the directory exists, use it.
  6. Use System.getProperty("java.io.tmpdir") and use it.

The easiest one is either #3 or #4, just create a work directory underneath your ${jetty.home} or ${jetty.base} and restart Jetty.

The next easiest is #6, to specify your own java.io.tmpdir when you start the JVM for Jetty.

[jetty-distribution]$ java -Djava.io.tmpdir=/var/web/work -jar start.jar

The rest require you to configure the context for that deployed webapp.

Example for Jetty 7 or Jetty 8:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
                           "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath"><Property name="foo"/></Set>
  <Set name="war">/var/web/webapps/foo.war</Set>
  <Set name="tempDirectory">/var/web/work/foo</Set>
</Configure>

Example for Jetty 9 (just a dtd change):

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
                           "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath"><Property name="foo"/></Set>
  <Set name="war">/var/web/webapps/foo.war</Set>
  <Set name="tempDirectory">/var/web/work/foo</Set>
</Configure>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...