java Jetty Home 系统属性未设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16695180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:41:06  来源:igfitidea点击:

Jetty home system property is not set

javajettysystem-properties

提问by user1226868

Im 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?

但是 jetty.home 总是返回空的。我如何设置这个变量并将它指向哪里?

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?

我的码头主文件夹是 D:\Developer Tools\jetty-6.1.26。需要指向这个文件夹吗?如果是这样,我该怎么做?我需要使用 Windows 全局变量吗?

Im using the org.eclipse.jetty.xml.XmlConfiguration class from org.mortbay.jetty.

我使用来自 org.mortbay.jetty 的 org.eclipse.jetty.xml.XmlConfiguration 类。

回答by Joakim Erdfelt

jetty.homeis set by Jetty's start mechanism.

jetty.home由 Jetty 的启动机制设置。

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

您正在使用 Jetty 6.1.26 (注意:Jetty 6.x 已被弃用,并于 2010 年终止)

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

虽然我不知道 Jetty 6 是如何工作的,但我知道 Jetty 7/8/9 在这方面是如何工作的。

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

更新:2019 年 8 月:Jetty 9.4.x 是 Jetty 当前稳定且积极支持的版本主线。

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

Jetty 启动机制(模块:/jetty-start/.aka start.jar)将根据(存在于 中的文件)中的一组规则建立jetty.home属性,然后使用类(也在 中定义)在对象中建立一组属性,然后加载在命令行上声明的 XML 文件和.start.configstart.jarorg.eclipse.jetty.xml.XmlConfigurationstart.configXmlConfigurationstart.ini

Problem #1: Mixed Jetty Versions

问题 #1:混合 Jetty 版本

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/contextdeclaration). They are 100% incompatible.

您有多种 Jetty 版本,它们可以工作,但不能跨 Jetty 6(如您声明的 Jetty 主文件夹中所示D:\Developer Tools\jetty-6.1.26)和 Jetty 7(如您的/etc/jetty7/context声明中所示)。它们是 100% 不兼容的。

Problem #2: Bad XML Syntax Use

问题 #2:错误的 XML 语法使用

Your XML syntax for working with paths is wrong.

您用于处理路径的 XML 语法是错误的。

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)
  1. 它是相对路径和绝对路径的混合,不会起作用。
  2. <SystemProperty>使用路径时,您必须始终声明使用时的默认值。(空默认无效)

Correct Syntax for Relative Paths

相对路径的正确语法

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

If your jetty.homeis 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

如果您jetty.homeD:\Developer Tools\jetty-distribution-7.6.11.v20130520,那么这将指向D:\Developer Tools\jetty-distribution-7.6.11.v20130520\etc\jetty7\context

If you don't declare jetty.homebefore using XmlConfigurationthen 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.diris D:\Code\MyProject, then the result would be D:\Code\MyProject\etc\jetty7\context

如果您jetty.home在使用前未声明,XmlConfiguration则将使用默认值,"."它将被转换为您当前的工作目录(也称为System.getProperty("user.dir"))加上您指定的硬编码相对路径。如果user.dirD:\Code\MyProject,那么结果将是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.homeand the result will always be /etc/jetty7/contexton unix and (highly likely to be) C:\etc\jetty7\contexton windows.

这种语法可能不太关心jetty.home,结果将始终/etc/jetty7/context在 unix 上和(很可能是)C:\etc\jetty7\context在 windows 上。