如何让 sbt 的 Jetty 使用本地域名?
我想要 sbt> 推出的 Jetty 版本~jetty
监听 my.name.local
,我已在 /etc/hosts
中将其设置为 127.0.0.1
。 似乎可以更改 Jetty 的设置从 sbt 内部。
以下是我的项目:
import sbt._
class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
// ...
val jetty = "org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "test"
override lazy val jettyInstance = new JettyRunner(customJettyConfiguration)
def customJettyConfiguration = {
val myLog = log
val myJettyClasspath = jettyClasspath
val myScanDirectories = scanDirectories
val myScanInterval = scanInterval
new CustomJettyConfiguration {
def classpath = jettyRunClasspath
def jettyClasspath = myJettyClasspath
def war = jettyWebappPath
def contextPath = jettyContextPath
def classpathName = "test"
def parentLoader = buildScalaInstance.loader
def scanDirectories = Path.getFiles(myScanDirectories).toSeq
def scanInterval = myScanInterval
def port = jettyPort
def log = myLog
override def jettyConfigurationXML =
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>my.name.local</Item>
</Array>
</Set>
</Configure>
}
}
}
虽然它似乎启动时没有任何抱怨,但据我所知,访问 my.name.local
并没有到达 Jetty。
I'd like the version of Jetty launched by sbt> ~jetty
to listen on my.name.local
, which I've set to 127.0.0.1
in /etc/hosts
. It seems to be possible to change Jetty's settings from within sbt.
Here's what I have for my project:
import sbt._
class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
// ...
val jetty = "org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "test"
override lazy val jettyInstance = new JettyRunner(customJettyConfiguration)
def customJettyConfiguration = {
val myLog = log
val myJettyClasspath = jettyClasspath
val myScanDirectories = scanDirectories
val myScanInterval = scanInterval
new CustomJettyConfiguration {
def classpath = jettyRunClasspath
def jettyClasspath = myJettyClasspath
def war = jettyWebappPath
def contextPath = jettyContextPath
def classpathName = "test"
def parentLoader = buildScalaInstance.loader
def scanDirectories = Path.getFiles(myScanDirectories).toSeq
def scanInterval = myScanInterval
def port = jettyPort
def log = myLog
override def jettyConfigurationXML =
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>my.name.local</Item>
</Array>
</Set>
</Configure>
}
}
}
While it seems to launch without complaints, visiting my.name.local
doesn't hit Jetty as far as I can tell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人更喜欢在 Linux 上使用 iptables 将端口 80 重新路由到 8080,而不是以 root 身份运行 sbt(这是危险的):
这仅在下次重新启动之前有效。为了使该设置在 Ubuntu 10.04 上保持不变,我使用:(
请参阅此 Ubuntu iptables wiki)
Rather than running sbt as root (dangerous), I personally prefer rerouting port 80 to 8080 using iptables on Linux :
Which works only until the next reboot. To make the setting persistent on Ubuntu 10.04, I use :
(see this Ubuntu iptables wiki)
我发帖太早了。我需要做的就是覆盖
jettyPort
:并通过
sudo
运行sbt
。I posted too soon. All I need to do is override
jettyPort
:And run
sbt
viasudo
.