Hot reloading with JAX-RS - java

I want to get a development experience like I get with Play! framework with JAX-RS (with Jersey for example). More specifically I want to use some kind of background compilation and run the compiled code immediately so that I have almost no waiting time.
My first attempt was to use NetBeans background compilation and Maven with plug-ins for Tomcat and Jetty which are restarting the application in the running container. But restarting took too long. I'm wondering if I need to restart the application if code changed or if something like Grizzly or Netty instead of a Servlet container would help.
Any ideas how to get fast reloads with JAX-RS?

Try this,
you need to add the dependencies. It uses jreloader (open source).
ant archetype
Edit:
People are still visiting this post after two years. Now there's a complete alternative for hot reloading and the project is active again http://dcevm.github.io/
You may need to use this as well https://github.com/HotswapProjects/HotswapAgent

Take a look at gretty: https://github.com/groovypp/gretty
It should work with jersey and you should see fast runtime reloads.

JRebel does this: http://zeroturnaround.com/jrebel/

Related

Difference between Hot redeploy in Play and automatic restart in Spring Boot

If I take a look at Hot redeploy in Play and Automatic restart in Spring Boot, it seems very similar. Is there any principal difference between implementation of these features in these projects?
In Play it's out of the box, while in Spring Boot you have to install the Dev-tools.
In Play you have to hit the reload button of your browser in order to reload but there is an awesome plugin made by James Ward which triggers a reload when you make changes to a file.
Warning personal opinion:
Working on both frameworks, using both plugins, the Play version is much cleaner and works better, save changes, see how the browser refreshes, immense productivity boost.
Also in performance, if your Spring application is a little bit bigger than usual, it takes a little bit longer, while in Play it's always fast.
They are essentially the same in terms of implementation in that they both create a new application classloader to load in the new changes and discard the previous one.
Note that here are a couple of options for running a Play application to trigger reload:-
The following will trigger a rebuild and reload of classloader when a new request is received by the application, namely when you hit refresh in your browser. James Ward's plugin just saves you have to hit refresh.
activator run
The following will monitor your source directories for changes and will automatically re-compile any modified source on the fly. Although the server has recompiled the source and setup a new classloader you still need to do a refresh in your browser to see the changes (or use an extension like James Ward's).
activator ~run

Using JSP Hot deployment for application that need frequent update

Is using JSP Hot deployment a solution to publish new or updated content to avoid restarting the Java EE server (cannot hot deploy jar)? I should not use JSP to code a lot of java, but do I have any other solution?
With Tomcat, you can use the Parallel Deployment method. You will be able to deploy your new version and keep older one running with every users that has a session on it.
It is really simple when you are using WAR files, I recommend a simple script to delete older versions after couple of days for exemple, just to keep only few running versions.
You can get more informations here : http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Parallel_deployment
Did you have a look at JRebel yet?

Spring Directory Listener

I'm creating a web application that uses Apache Tomcat (Latest), Spring 3, Struts2 and Hibernate. I need to have a listener that observes a directory for any new XML files that appear. While the web application is deployed onto Tomcat and running it should keep doing this.
What method is recommended when doing something like this, using these frameworks?
Are there any examples that I can look at to assist with the beginning stages?
Try jdk7 WatchService. I have already done it a project which has a similar structure to the one you have. Otherwise you could try to use FileAlterationListner from org.apache.commons.io. I would rather go for jdk7 as it worked perfectly.
i have used JNotify in one of the project, it worked like charmed, if switching to JDK 7 is not possible.

Can I hot-deploy apps into Tomcat?

I'm wondering is it possible to "hot develop" spring application.
For example. In Play framework when I change something in template or even controller or configuration I don't need to republish the application or restart server. I just refresh the page.
Is this kind of quick and easy work is possible with spring framework ? Does it depend of server?
If you want true hot (re)deployment you'll probably need to use something that modifies Java class-loading like JRebel.
Spring itself doesn't tell much about redeployment and stuff, but in most cases you can reload your templates without restarting depending on your ViewResolver.
Furthermore in some environments (for example in OSGi) it is possible to hot-deploy classes, resources and nearly everything. Having a properly configured SpringSource Tool Suite and eg. Virgo WebServer it is possible to achieve hot deployment and as such you can reload the running classes as you save them.

How to start/stop bundles in OSGI based web application

Usually we start/stop bundles via OSGI console, but for web application, how to do that once it's deployed in a container ?
Regards,
Setya
Also not sure if I got you right, but anyway:
I think it depends on how you deploy a OSGi web application. The only way I already did was that I ran Tomcat within the OSGi context. Then Tomcat scans for bundles with a ".war" ending, so its basically started as soon as it's deployed and you can control it normally via the OSGi console
not sure If I got you right, but...
Mostly applications are started just after deployment(war or eclipse)... you don't need to do anything.
but in case you want to you can do exactly the same thing you do to bundles... go to the web console of your chosen AS and start it there.
Depends what you're using - please update question with container/framework details.
Otherwise, using Karaf you may simply SSH into the framework's shell and execute commands as normal.
Another alternative would be to use WebConsole from Apache Felix - this gives you a lot of control wrt bundles (you can even upload to deploy), and also gives you an embedded shell. It's quite extensible, you can write plugins to create new tabs etc. (AFAIK this will run fine in any framework).

Categories

Resources