如何在Debian服务器上连续自动运行.jar? [英] How to run .jar continually and automatically on Debian server?

查看:680
本文介绍了如何在Debian服务器上连续自动运行.jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .jar 文件我想一直在 Debian 服务器上运行。

I have a .jar file I want to run all the time on a Debian server.

目前我已经找到了如何通过 ssh 访问服务器 Cygwin 并启动 .jar 。但是当我关闭我的开发机器上的Cygwin窗口时,它会杀死服务器上的进程(我想,因为它不再响应)。

Currently I have figured out how to access the server via ssh on Cygwin and start the .jar. But when I close the Cygwin window on my development machine, it kills the process on the server (I think, as it's not responding any longer).

目前我启动它像这样:

java -jar myjar.jar packageName.fileNameOfFileWithMainMethod

我需要让这个文件在服务器上自动运行(它是我正在开发的系统中不可或缺的一部分)。

I need to make this file run automatically and continually on the server (it is an integral part of the system I am developing).

不幸的是,我对服务器管理或非Windows操作系统一无所知(不是我选择或制造服务器的人),所以我真的不知道该做什么,也不知道该做什么要搜索什么(显然,因为我的搜索没有给出有用的结果)。

Unfortunately I know next to nothing about server management, or non-windows operating systems in general (wasn't me who chose or made the server), so I really don't know what to do, nor what to search for (apparently, since my searching gave no usable results).

我已阅读(并且因为文字很乱而编辑)这个问题,但是虽然我觉得它可能暗示着正确的方向,我没有得到很多帮助。我也尝试了我最好的googlefu,但它让我得到了许多与切向相关的结果。

I have read (and edited because the text was a mess) this question, but although I feel it might be hinting in the right direction, I didn't get much help from it. I also tried my best googlefu, but it got me a lot of only tangentially related results.

我想我必须制作某种脚本(可能包含上面的代码行),做一些事情并把它放在服务器上特定的地方,以完成我想要做的事情。

I guess I'll have to make some kind of script (possibly containing the code line above), do some stuff to it and put it somewhere specific on the server to accomplish what I want to do.

有人会如此善良地解释如何这样做了吗?

Would someone be so kind as to explain how this is done?

推荐答案

一个简单的建议是使用Linux的 CRON

One simple suggestion would be to run the jar file using Linux's CRON.

这篇来自unix堆栈交换的文章应该让你为运行jar文件找到正确的方向使用cron。

This article from unix stack exchange should get you going the correct direction for running a jar file using cron.

或者,来自mkyong.com的这篇文章也很简洁明了。

Alternatively, this article from mkyong.com is also clear and concise.

例如:


  1. 使用Cygwin连接

  2. 运行 crontab -e

  3. 输入 0 * * * * java -jar myjar.jar packageName.fileNameOfFileWithMainMethod 每小时运行一次jar文件。或者,要在服务器启动时启动一次,请输入 @reboot java -jar myjar.jar packageName.fileNameOfFileWithMainMethod

  1. Connect using Cygwin
  2. Run crontab -e
  3. Enter 0 * * * * java -jar myjar.jar packageName.fileNameOfFileWithMainMethod to run the jar file every hour at the top of the hour. Or, to start it once on server startup enter @reboot java -jar myjar.jar packageName.fileNameOfFileWithMainMethod

这篇关于如何在Debian服务器上连续自动运行.jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆