嵌入式 Jetty:设置 JVM 参数
我的应用程序中运行着一个嵌入的 Jetty 实例,它显然创建了另一个 JVM 实例。如何将 JVM 参数传递给该实例?我像这样创建嵌入式 Jetty:
val server = new Server
val scc = new SelectChannelConnector
scc.setPort(8080)
server.setConnectors(Array(scc))
val context = new WebAppContext()
context.setServer(server)
context.setContextPath("/")
context.setWar("src/main/webapp")
server.addHandler(context)
try {
println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP")
server.start()
while (System.in.available() == 0) {
Thread.sleep(5000)
}
server.stop()
server.join()
} catch {
case exc:
Exception => {
exc.printStackTrace()
System.exit(100)
}
}
(Scala 代码,但我相信 Java 开发人员也很容易理解)
I have an embedded instance of Jetty running in my app, which apparently creates another instance of JVM. How can I pass JVM arguments to this instance? I create my embedded Jetty like this:
val server = new Server
val scc = new SelectChannelConnector
scc.setPort(8080)
server.setConnectors(Array(scc))
val context = new WebAppContext()
context.setServer(server)
context.setContextPath("/")
context.setWar("src/main/webapp")
server.addHandler(context)
try {
println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP")
server.start()
while (System.in.available() == 0) {
Thread.sleep(5000)
}
server.stop()
server.join()
} catch {
case exc:
Exception => {
exc.printStackTrace()
System.exit(100)
}
}
(Scala code but I believe it's easy to understand for Java devs as well)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样在 Jetty 中启动服务器不会导致创建新进程。如果要设置影响嵌入式 jetty 服务器的 jvm 参数,您需要确保创建服务器的进程使用适当的设置运行。或者,您可以启动一个进程,并正确设置所有内容,但这将需要一些额外的工作来监视进程等。
Starting a server in Jetty like this will not result in a new process being created. If you want to set jvm parameters that affect the embedded jetty server you need to ensure that the process creating the server is run with the appropriate settings. Alternatively, you could launch a process having setup everything appropriately but this will require some additional work to monitor the process, etc.