Can I hot-deploy apps into Tomcat? - java

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.

Related

Hot reloading with JAX-RS

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/

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).

Spring MVC Plugin Architecture

I am a novice with JavaEE but have some experience with ASP.NET MVC. With ASP.NET MVC, I know we can make a plugin architecture with ASP.NET MVC web app so you can make a dll with MVC structure and put it into the existing ASP.NET MVC web app to make it work without compiling the web app. http://www.wynia.org/wordpress/2008/12/05/aspnet-mvc-plugins/
I wonder if this kind of architecture is possible with Spring MVC. For example, when I make a jar (or war) file with MVC structure and put it into existing Spring MVC web app, it should work without recompiling the web app. If this is possible, how can I achieve that? Any reference would be appreciated.
It is possible without recompiling, but probably not without restarting. You could create a .jar which you drop into the WEB-INF/lib directory. By using classpath scanning you should be able to deploy your new controllers on start-up. You can skip the view entirely and directly output data to the ServletResponse. Rendering a view from a jar may or may not be possible, I don't know.
Sounds like you want to search for "hotdeploy".
What you are asking for is not a feature of Spring, but rather a feature of JVM and the application server. The application server is able to see that indeed your classes have changed and using some clever ClassLoader trickery it can load new versions to the runinng JVM as they become available. Java was not actually designed to work like this so there are some issues (ClassLoader, memory leak, hotdeploy are good keywords for finding more about the potential problems and possible solutions). I would not recommend this for production use but it can be handy during development.
Since this is a feature of the application servers, the actual details depend on the particular application server and are explained in it's documentation.
If you simply want some plugin-magic, not actual hotdeploy, there are other things you could do. A custom ClassLoader can load classes from whatever source (file, network, database..) you want and then you can instantiate and use these with reflection. (This is what happens when you deploy the war to Tomcat/JBoss or whatever). Accessing and dynamically reloading non-class resources inside jar/war files is way easier.

Can you get jboss weld to continually scan for newly added classes during development?

i'm setting up a JSF2 project on tomcat 6.0.29 with weld. also using jrebel - not sure if that makes a difference.
In testing out JRebel i can see that updating classes that existed when the container was started are handled fine.
however, if i ADD a newly defined CDI component class and re-explode the app without restarting the appserver, i can't access it from the facelets till i restart. JRebel seems to be loading the class in, so i'm guessing weld isn't registering it in the beanmanager
i realise that CDI is meant to hook up the config on startup, but it would be good to have some sort of dev switch to enable continuous scanning the same way JSF has a dev mode that picks up changed facelet templates.
this and the functionality that JRebel provides would be an awesome productivity boost.
can this be done? had a quick look at the weld docs but can't find anything.
thanks.
I don't think so. But adding new beans would be something rare, compared to changing existing ones. And that doesn't require restart.

Is it possible to include/embed one Java EE application(war file) inside another?

I have an application which is a portal application and I want to allow other users add their applications to it. In order to do this I need some way to be able to access their applications in mine. Is this possible?
You cannot put WARs inside of other WARs. You need an EAR file to contain WARs, EJBs, etc. One way to implement inter-WAR communication is to package that logic directly in the EAR. It all depends on what you're trying to do.
the way to do inter .WAR communication is by the method
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getContext(java.lang.String)
ServletContext.getContext(URIOfOtherWAR_resource)
I've used this succesfully for doing what you're talking about.
Maybe you need a plugin system or portlet, so your user will not develop a war application but include their portlet inside your application (war). There's a standard : JSR 168 and several implementations :
http://developers.sun.com/portalserver/reference/techart/jsr168/
As others have pointed out, embedding WARs inside WARs is not an option. However, I may have a workaround for you.
Most Web containers I'm familiar with have a "test deployment / auto deploy" mode / capability, where they will automatically deploy an application if the WAR is copied into the right directory.
Your portal application could certainly allow uploading WARs, and it could store the uploaded bytes in a given directory under a given file name. Your Web container could do the rest. You could then link to the new application from your portal, or whatever. All this is relatively easy to do.
However, be advised that this is a horrible idea if there is any security concern whatsoever. You are essentially allowing your users to execute arbitrary code on your server. Unless you completely trust all potential users to be both non-malicious and perfectly competent (think infinite loops), you are asking for a lot of trouble here.

Categories

Resources