开发者

Java framework for hot code deployment and scheduling jar file deployment

开发者 https://www.devze.com 2023-02-07 00:00 出处:网络
Using JAVA framework i want to achieve the following task. hot code(jar) deployment which will perform certain task in an environment

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 ?


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?


Give JRebel a try. It is a great tool.


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);
        }
    }

}


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.


  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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消