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
Jetty home system property is not set
提问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.home
is 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.home
property based on a set of rulesin 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
.
Jetty 启动机制(模块:/jetty-start/
.aka start.jar
)将根据(存在于 中的文件)中的一组规则建立jetty.home
属性,然后使用类(也在 中定义)在对象中建立一组属性,然后加载在命令行上声明的 XML 文件和.start.config
start.jar
org.eclipse.jetty.xml.XmlConfiguration
start.config
XmlConfiguration
start.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/context
declaration). 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>
- It is a mix of relative and absolute paths and will not work.
- You must always declare a default value on
<SystemProperty>
use when working with paths. (empty default is invalid)
- 它是相对路径和绝对路径的混合,不会起作用。
<SystemProperty>
使用路径时,您必须始终声明使用时的默认值。(空默认无效)
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
如果您jetty.home
是D:\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.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
如果您jetty.home
在使用前未声明,XmlConfiguration
则将使用默认值,"."
它将被转换为您当前的工作目录(也称为System.getProperty("user.dir")
)加上您指定的硬编码相对路径。如果user.dir
是D:\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.home
and the result will always be /etc/jetty7/context
on unix and (highly likely to be) C:\etc\jetty7\context
on windows.
这种语法可能不太关心jetty.home
,结果将始终/etc/jetty7/context
在 unix 上和(很可能是)C:\etc\jetty7\context
在 windows 上。