如何在没有控制台的情况下运行java程序
即使终端关闭,我也需要运行java程序...... 在服务器中....
I need to run an java program even the terminal is closed....
in server....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
即使终端关闭,我也需要运行java程序...... 在服务器中....
I need to run an java program even the terminal is closed....
in server....
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
在 Unix 和 GNU/Linux 系统上,您可以像这样使用
nohup
运行程序,假设它是一个 jar:要将程序的输出运行到文本文件中,这样稍后你可以查看它,你可以这样做:
有些包也可以将你的Java程序包装成服务,这比裸露的
java
进程更易于管理。您可能还想使用“进程包装器”(Launch4J 也许?)给你的进程起一个有意义的名字,否则你所有的Java程序都会在进程列表中显示为
java
,这不是很有指示性。On Unix and GNU/Linux systems you can run the program using
nohup
like this, assuming it is a jar:To get the output of the program run into a text file so later on you can view it, you can do:
There are packages that will wrap your Java programs into services too, which is more manageable than bare
java
processes.You probably also want to use a "process wrapper" (Launch4J maybe?) to give your process a meaningful name, otherwise all your Java programs will appear as
java
in the process list, which isn't very indicative.nohup
的“替代方案”是screen
。screen
非常有用,它允许您运行任何任务、分离屏幕并让它在后台运行。您可以稍后恢复。An "alternative" to
nohup
would bescreen
.screen
is very useful and allows you to run any task, detach the screen, and let it run in the background. You can resume it later.使用 javaw 命令而不是
java
.Use the javaw command instead of
java
.您想要使用无头模式。这将导致任何尝试与屏幕、键盘、鼠标等通信的调用失败,但也意味着您不需要 X 服务器(在 Unix 上)或访问控制台(在 Windows 上)。
You want to use headless mode. This will cause any calls that attempt to communicate with a screen, keyboard, mouse, etc to fail, but also means that you won't need an X server (on Unix) or access to the console (on Windows).