每天在特定时间运行jar文件的解决方案 [英] Solution to run a jar file at specific time each day

查看:159
本文介绍了每天在特定时间运行jar文件的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分发一个需要定期运行的jar脚本。我不知道最终用户将使用哪个操作系统。

I am want to distribute a jar script that needs to run periodically. I don't know which OS the end user will have.

我是否可以使用跨操作系统解决方案在每天的特定时间运行jar文件。

Is there a cross OS solution that I can use to run a jar file at a specific time each day.

也就是说,在windows中它会添加一个计划任务和一个cron任务等。

That is, in windows it adds a scheduled task and a cron task etc.

任何帮助表示感谢!

推荐答案

您可以使用用Java编写的任务调度框架来保证跨操作系统的可移植性 - 因为每个操作系统都有自己的调度命令,你不会在不同的平台上找到相同的工具。

You could use a task scheduling framework written in Java, for guaranteeing portability across OS - because each OS has its own scheduling commands, you won't find the same tools across different platforms.

例如,看看石英。但要注意,你必须学习如何使用它来配置,设置和编程任务,恕我直言,它不是 简单。但话说回来,这就是你需要为便携性支付的价格。

For instance, take a look at Quartz. But be warned, you'll have to learn how to configure, setup and program tasks with it, IMHO it's not that simple. But then again, that's the price you have to pay for portability.

另一种选择是使用计时器服务(请参阅教程) ,但为此你需要一个兼容Java EE的服务器。无论哪种方式都注意到运行jar实际上意味着在jar文件中执行main方法,这只是对Java程序的调用。

Yet another option would be to schedule a task using a Timer service (take a look at the tutorial), but for that you'll need a Java EE compliant server. Either way notice that "running a jar" really means executing the main method in the jar file, which is just a call to a Java program.

这篇关于每天在特定时间运行jar文件的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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