用于热代码部署和调度 jar 文件部署的 Java 框架

发布于 2024-10-14 16:45:19 字数 239 浏览 5 评论 0原文

使用JAVA框架我想实现以下任务。

  1. 热代码(jar)部署将在环境中执行某些任务
  2. 。任何时候,如果我更新该 jar 文件,它应该自动卸载旧代码并加载新代码,
  3. 我想安排已部署的 jar 文件来执行任务。

目前我看到 Apache karaf/Felix 满足了这一要求,但可用的帮助较少且难以管理。

我可以使用任何替代框架来代替 karaf/felix 吗?

Using JAVA framework i want to achieve the following task.

  1. hot code(jar) deployment which will perform certain task in an environment
  2. At any time if i update that jar file it should automatically unload old code and load new code
  3. I want to schedule that deployed jar file to perform tasks.

Currently i see Apache karaf/Felix fulfill this requirement but less help available and difficult to manage.

Any alternate framwork i can use instead of using karaf/felix ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

过气美图社 2024-10-21 16:45:19

如果你不打算走 OSGi 路线,你基本上是通过放弃 Karaf / Felix(Karaf 默认使用 Equinox)来暗示的,​​那么我可以建议你考虑的最好的事情就是 LiveRebel 发布时。 @Daniel 的回答提到了 JRebel,它在开发过程中的热部署方面非常出色,但它并不是一个工具。对于生产系统。相反,您应该查看同样由 Zero Turnaround 制作的 LiveRebel,也许能够满足您的需求。请注意,这是一个商业产品,但他们现在提供私人测试版。


[编辑]

白痴的是,我忘了提及还有 Knoplerfish,另一个具有 BSD 的 OSGI 运行时风格许可证。也许尝试一下?

If you aren't going to go the OSGi route, which you basically implied by forgoing Karaf / Felix (and Karaf uses Equinox, by default) then about the best thing I can suggest for you to consider is LiveRebel when it comes out. @Daniel's answer mentioned JRebel, which is outstanding for hot deployment during development but it is not meant as a tool for production systems. Instead you should check out LiveRebel, also made by Zero Turnaround, might be able to fulfill of your needs. Please note that this is a commercial product but they are offering a private beta right now.


[Edit]

Idiotically, I forgot to mention that there's also Knoplerfish, another OSGI runtime which has a BSD style license. Perhaps give that a shot?

美人迟暮 2024-10-21 16:45:19

尝试一下JRebel。这是一个很棒的工具。

Give JRebel a try. It is a great tool.

蓝礼 2024-10-21 16:45:19

请注意您所指的环境(例如网络、桌面、服务器端等),但是……

逆向工作:

3:计划任务
您可以使用 Quartz Scheduler 库 在任何 Java 容器中实现此目的。这允许您以类似 CRON 的方式安排事件。

1-2:热部署
那么就是你要部署在哪里以及如何处理热部署的问题。其他答案提到了 JRebel 和 OSGI 可以工作。如果您想要一些超快速的部署(例如,保存代码并使其可用)并将其托管在 Web 容器中,则使用 播放框架。它使用 Quartz 以非常好的方式实现计划作业

例如(来自 Play 文档):

@Every("1h")
public class Bootstrap extends Job {

    public void doJob() {
        List<User> newUsers = User.find("newAccount = true").fetch();
        for(User user : newUsers) {
            Notifier.sayWelcome(user);
        }
    }

}

Note sure what environment you mean (eg. web, desktop, server-side, etc), but...

Working backwards:

3: Scheduled Tasks
You can achieve this in any Java container with the Quartz Scheduler library. This allows you to schedule events in a CRON like fashion.

1-2: Hot Deployment
Then it's a question of where you want to deploy and how to handle hot deployment. Other answers have mentioned JRebel and OSGI which will work. If you want some super quick deployment (eg. save the code and it's available) and have it hosted in a web container ,then use the Play Framework. It uses Quartz do implement Scheduled Jobs in a very nice way.

For example (from the Play docs) :

@Every("1h")
public class Bootstrap extends Job {

    public void doJob() {
        List<User> newUsers = User.find("newAccount = true").fetch();
        for(User user : newUsers) {
            Notifier.sayWelcome(user);
        }
    }

}
£烟消云散 2024-10-21 16:45:19

JBoss 具有您所描述的热部署功能。然而,我猜配置 Karaf 也很复杂。不过,也许可以了解 JBoss 如何实现它并自己使用这些库。

JBoss has the hot deploy feature that your describing. However, I'm guessing it's as complicated to configure Karaf. It may be possible to find out how JBoss is achieving it and use the libraries yourself though.

著墨染雨君画夕 2024-10-21 16:45:19
  1. 热代码(jar)部署,它将在
    环境
  2. 任何时候,如果我更新该 jar 文件,它都会自动卸载
    旧代码并加载新代码
  3. 我想安排已部署的 jar 文件来执行任务。

简而言之,热部署/重新部署是这样完成的:

  • 使用类加载器(java.net.URLClassLoader 是一个好的开始),加载 jar,实际上在加载之前将 jar 复制到某个地方(临时)
  • 您需要一些接口实现,实例化实现接口的类(jar 中的 META-INF,自定义 xml,等等),配置它(props/xml,等等)
  • 调用 start() 并执行任务。
    <小时>
  • 监视 jar:一些线程每秒检查它并比较上次修改的时间/大小
  • 如果更改 - 调用 stop() 并取消部署,可能需要等待线程等,重新开始

有很多允许动态部署的框架

  1. hot code(jar) deployment which will perform certain task in an
    environment
  2. At any time if i update that jar file it should automatically unload
    old code and load new code
  3. I want to schedule that deployed jar file to perform tasks.

In a nutshell, hot deploy/redeploy is done like that

  • Use a classloader (java.net.URLClassLoader is a good start), load the jar(s), actually copy the jar somewhere (temp) before loading it
  • You need some interface implementation, instantiate the class implementing the interface (META-INF in the jar, custom xml, whatever), configure it (props/xml, whatever)
  • call start() and perform the tasks.

  • Monitor the jar: some thread to check it each second and compare the last modified time/size
  • If changed - call stop() and undeploy, may need to wait for threads, etc, start over

There are a lot of frameworks that allow dynamic deploy

裸钻 2024-10-21 16:45:19

大多数 Web 容器(如 Tomcat 或 Jetty)的热部署功能允许您在 Web 应用程序上实现您想要的行为。

这样的应用程序可以非常简单,本质上只包含您的 jar。

您需要您的应用程序做什么?

The hotdeploy feature of most web containers (like Tomcat or Jetty) allow you to have the behaviour you want, on web applications.

Such an application can be very simple, and essentially just contain your jar.

What is it you need your application to do?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文