Refresh backend in GWT development - java

I am developing a GWT application that uses EJB and other Java EE 6 technology as the backend. I am currently using the GWT 2.0 plugin for Safari.
When I change my GWT client side code and save in my IDE (NetBeans), all that's required is a simple reload in the browser for the changes to become active. That works great!
However, often I work on the server-side (the EJBs, GWT server code, etc) and then something in on the GWT client side. Any changes done to the server-side do not appear to incrementally deploy to the Glassfish V3 server. Currently I close the GWT Development Mode application, and then recompile the EJBs, and then go back into GWT Development mode. That is tedious.
Any better way of doing this? I tried the "deploy on save" option in NetBeans but it does not seem to do the trick.

The trick is to create an exploded ear directory (instead of an ear file) and deploy that in your application server. It works in JBoss and Weblogic, and should work in glassfish, but haven't tried it.
The idea is that you don't use any archives at all. In you war directories, create a WEB-INF/classes folder, and configure your IDE to write the class files in this directory. That way, when you change a java file in your IDE, it will write to your classes directory and the JVM will hot-deploy your classes.
There are some restrictions with this approach. If you change a method signature or add a class or new method, JVM cannot pick it up. In such cases, touching web.xml redeploys the WAR. This in itself is an improvement from restarting the entire application server.
It takes an hour or two to get the right setup, but after that you will just love it.

Related

Hot code deployment in Jetty

I am writing a Java EE application, using Jetty as the app server for convenience during development. Although (re)deployment is fast, I'd like if it was possible for Java code changes to be reflected immediately in the running server without restarting. (I'm already using the useFileMappedBuffer setting to see immediate changes to statically served content).
I've seen questions about using the Maven Jetty plugin and setting scanInterval in order to redeploy a web context, but that's not what I want to do. My Jetty server is started from within a Java application in Eclipse and I'd like code changes to be immediately reflected in the running server, as is possible with ordinary Java applications in Eclipse. I'm running the code "in place", i.e. not building and deploying a WAR file first.
I realise that web apps have their own class loaders in order to conform to the servlet spec, but I don't mind risking non-standard behaviour to get changes deployed more rapidly in development. I've tried using WebAppContext.setClassLoader to set the classloader to a "normal" classloader but to no avail.
Is it possible to do what I want? I believe JRebel claims to do it, but what's it doing that I'm not?
If you connect to Jetty using remote debug from Eclipse, Hot code replace should be possible.
Remote debugging is enabled by adding following to Jetty start script:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787
Even the ordinary Java application needs to be restarted to see code changes.
Basically your options are:
Restart Jetty (you said you don't want that).
Make Jetty scan for application changes and allow hot redeploy if changes are detected (you said you don't want that).
Attach a remote debugger which then does hot-swap your code changes (see answer of Amila). This is limited to method body changes and therefore not really useful.
Use JRebel which provides a useful hot-swap implementation and also can pick up configuration changes for many frameworks.
Use a web framework which implements a proprietary hot-swap implementation based on throw-away-classloaders (e.g. Tapestry or Civilian).

How to deploy java application on different server?

If i want to deploy one application on different servers like Open Source Glassfish or TomEE. How can I achieve that without having to include different libraries for each application server? As an example if would like to use Jersey as the rest framework and eclipselink as the persistence framework i have to make sure both support these frameworks. But in case of TomEE it's shipped with other implementations like OpenJPA.
Is it possible to ship the dependencies only with the project and not in combination of server libraries + project libraries?
What is a good way to achieve server compatibility?
Any information or link which describes a solution or help me understand why it's done this way would be great.
Thanks in advance
This is more of a application server classloading issue and usually all application servers have a provision for a configuration file which you can put in your application and instruct the server to load the libraries included in the web application instead of the one present in application server. For e.g., Weblogic has a weblogic.xml file which is put in WEB-INF of war application and where you can instruct server to prefer the application packaged libraries. For JBoss there is similar configuration file jboss-deployment-structure.xml. This way it is easier to have a self contained application which contains all dependencies even if the server has equivalent libraries. Also you can upgrade to higher version of libraries than supported by application server otherwise you have to resort to all sort of hacks.
Easy solution I can think of is using ant task to create war file for each servers. You can have at most 2-3 servers in reality like tomcat ee, jboss and glasfish. So create 3 ant tasks for each like tomcatWar, jbossWar and glassfishWar and each ant task makes sure required jars are shipped as well in the war. This is more easy and extendable solution, also easy to understand and modify for new requirements.

Java web development without Eclipse

I'm interested in doing some Java web development but I'm not really interested in using Eclipse. I have used Eclipse in the past and to me it seems to add a layer of abstraction that I'm not really interested in. However, I'm having a bit of upstart problems.
Does anyone have any good references/tutorials in getting up and running with Java web development without using Eclipse (or any other IDE for that matter)?
Create a maven project and use one of the embedded web servers like jetty or Glassfish.
Also, this approach allows you to work with the command line directly or use either Netbeans, Eclipse or IntelliJ as your IDE as they support Maven projects. I do not think that JDeveloper can yet.
(Eclipse may require the m2e plugin from the marketplace, and it handles all the Eclipse configuration transparently and directly. Highly recommended).
You can easily do java web development using notepad only. The extra work is, you have to write some extra code (like in servlet you have to write web.xml http://www.tutorialspoint.com/servlets/servlets-first-example.htm). Same in Struts, Hibernate and Spring framework, you have to write config file in notepad.

How to configure WTP/Eclipse and Maven for multiple webapps that share resources

I'm trying to figure out the best maven configuration for a unusual web app configuration.
We have two web apps that we are migrating to maven. We use Eclipse as our IDE.
The structure is as follows, we have a main web app that has all the normal web app information. A standard config as far as Eclipse WTP and Maven are concerned. Then we have a second web app that contains everything that the previous web app but in addition it extends classes/creates new ones, overrides jsp files and adds additional ones. In addition we have shared resources that both web apps import.
We currently have a very complex ant build script that handles this. I was thinking of setting it up as different webapps in Eclipse (and finding a way to share the resources) or as a multi-module app (not sure how to handle two web app modules), but I'm not really sure how to set it up or if there is a better solution.
If the two applications must live on the same server you could put both your applications inside an EAR. Beware that different application servers have different opinions on how class loading should be handled. In my experience WebSphere 7 follows J2EE specifications more strictly than JBoss 5.1; I have no specific experience with other products and/or versions.
If this is not the case and your applications only share resources at development time, WAR overlay may be an approach worth exploring.
Both approaches should be supported by both Maven and the WTP addon for the m2eclipse plugin, but these things are evolving right now and you'd better do some experiments before committing to this route.

Should I use Eclipse wizard to deploy web application?

I use Eclipse "Dynamic Web Project" to create and test web application. It will publish my application on application server in convenient way. I don't need to write script, just wizard.
However, I am wondering it is a decent way to deploy a web application. What's your opinion? Thanks!
(I used to use Ant script to deploy my application, it's standard way.)
plus: Dynamic Web Project uses its specific directory layout which is different with Maven standard directory layout.
This is fine for deploying to a dev or test server. Its a convenient way to quickly deploy to have a look at changes you've made and to do tests.
I would definitely not allow this for any other environment, eg live, pre-production etc. You should have an established process (eg documented change control) to deploy to these environments.
I have heard it's still recommended to cold deploy and restart the server for not having a trouble with memory leaks, dynamic class loaders. For myself I think comfortable to deploy from Eclipse to most environments. Basically Eclipse WTP server adapter can run the same deploy command as the other processes. When I use clouds like GAE or Beanstalk I do deploy from Eclipse plugin, it is the same like command line.

Categories

Resources