JHipster Java web app development and its hot reload capability - java

I currently use the Play framework using Java (actually the 1.x series) and by far the best part of using Play, what makes it hugely productive is it's inherent, transparent, comprehensive, quick, seamless 'hot reload' capability. I simply could not return to doing Java development where I don't have this.
I do however have issues with Play in general including, but not limited to, the general lack of emphasis on Java as opposed to Scala development on the platform.
So doing a bit of research on current alternatives (I previously used to do Spring J2EE development) I stumbled across JHipster which on the surface looks promising.
So can people tell me the options of using JHipster with an 'easy' hot reload setup. Are we talking about using JRebel (which is expensive) or are there other alternatives? Is it straightforward to setup and does it work consistency? Anyone who has experience of this, I would be grateful for their comments.

JHipster gives you 2 types of "hot reload" features. They are both free and Open Source, and work consistently. I know lots of people (including me) using them daily.
The Spring Boot devtools allow you to have hot reload of your Java code. This is quite close to what Play! or JRebel provide. It has also been improved by JHipster to include database updates using Liquibase, something that JRebel or Play do not provide.
BrowserSync, which gives you hot reload of your front end (AngularJS) code. This is a very different focus: this means your Web browser gets automatically refreshed when code is changed.
It is the consistent usage of both those "hot reload" features that makes JHipster powerful. I often generate big parts of my application, and I have the database, Java code, and browser all refreshed automatically on-the-fly.

I'm in the same corner than you, looking for something better than play one in the java space, it has not been an easy task, we continue using play 1.4.1.
But going to your question, like you, we finally get to Spring Boot and to JHipster; Mat Raible presentation in Devoxx is very convincing.
For hot reload of Thymeleaf Templates, it's neccesary to add next two lines in application.properties:
spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5
Hot Reload Java
To have hot reloading in spring boot it's necessary to use the spring loaded project, download it and and let it somewhere in your disk.
To activate spring loaded, at least in Spring Tool Suite (eclipse) you need to add the jar as an agent in section VM Arguments of run configuration:
-Djava.security.egd=file:/dev/./urandom -javaagent:/home/hans/Descargas/springloaded-1.2.5.RELEASE.jar -noverify
It's not as cool as play one, it's necessary to restart the server from time to time, but it works.

Related

How to implement hot swapping (not automatic restart) in spring boot?

Hot reloading can be achieved by using spring dev tools
example https://dzone.com/articles/spring-boot-application-live-reload-hot-swap-with
but is there any way to do achieve true hot swap in spring boot. i know we can do automatic restart with spring boot dev tools . but i do not want to restart(i.e automatically/manually) the server every changes i make. i just need to update the byte code of java class i made change..
Hot reloading can be achieved by using spring dev tools
To an extent yes. As stated in the docs (emphasis mine)
Since Spring Boot applications are just plain Java applications, JVM hot-swapping should work out of the box. JVM hot swapping is somewhat limited with the bytecode that it can replace. For a more complete solution, JRebel can be used.
Ref: https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-hot-swapping
So you'll want to configure JRebel with Spring Boot for more advanced hot swapping. There are a plethora of tutorials out there.

Java single code base for desktop and mobile

Is there one or several java based technology that can help me write an application code base once (including Logic-Views-Controllers) and then compile and run it for
all platforms including main desktop and mobile operating systems as well as
in the browser. It must work and save in offline mode too so that it could sync with remote server as soon as it is connected to the internet. To me, it seems there must be a way if I use some sort of html/css/js technology to handle my views for such an application since I don't need fancy operating system dependent view technologies, and java for Logic and controllers. So far I have found Oracle ADF Mobile which seems to be commercial, eclipse RAP, eclipse scout .... But I look for something that covers Desktop as well. In addition if I can make the application run only in web browser, in case it would run and save in offline mode, it would be fine enough for me.
You could use Eclipse Scout for this with the following setup/limitations:
Since June 2016 Scout only supports web UIs (until 2015 Scout also had support for Swing/SWT, but this is gone now)
You would need to run the Scout frontend model part in a local Tomcat
or similar
You would need to add the sync code for connecting the Scout frontend
model with the Scout backend (that would sync data once a client installation gets online)
Asking for a mobile solution in combination with Java will most likely put you in a messy situation, especially with the discontinuation of RoboVM
Hint: The Scout team has started working on JS offline capability of the Scout UI. However, this is effort is still many months away from production quality (many parts/concepts still missing, not all parts open source, no documentation, etc.)
Addition: You will have the same limitations with Eclipse RAP (needs a frontend server, only web based, hint: styling rap apps is hard).
Looking for the silver bullet... Beware that "not caring about something" (the OS) will make you care a lot about a framework that does the "dirty work".
Leaving opinions aside, in 2016 you will reach your goal quicker with JavaScript, it has become the only thing supported everywhere.
It may be a good deal if you're OK with JS, and living on the bleeding edge with heterogeneous / less mature tooling (see NPM gate).
Java in the browser (applets) is dying soon due to its well documented security issues. One could argue it's been dead for a long time.
If you do want to code in Java only, GWT is still alive. It compiles your Java code into highly efficient JavaScript.
However, ever since Google reduced its involvement by giving away the project to a steering committee, the developments have slowed down drastically, and I'm not even sure they are up to date with JDK 8 yet.
Google still uses GWT in projects like inbox, for what it's worth.
I would go with GWT.
Google also uses this for projects like the inbox webapp, and the inbox android app. Using GWT a lot of code between the two apps can be shared.
It is also possible to compile as a windows desktop application.

How to quickly and efficiently test project on Tomcat local server after making changes

I'm trying to build a Dynamic Web Application in Eclipse and I'm having trouble when I test my changes.
Sometimes when I make changes, I relaunch the Tomcat server and behold, my project looks exactly the same as last time. I then clean and rebuild the project a few times as well as clean the server, and finally my changes are visible.
This is time consuming and doesn't feel correct.
Is there a proper, quicker, more efficient way to launch a clean copy of your project on the local server?
I have used the Eclipse Tomcat plugin for years with no issues and more recently the Spring Tools Suite with plugin for their customized Tomcat. As you say having your project Build Automatically and having the Server configuration, via the plugin, set to Publish Changes Automatically goes some way towards alleviating the pain of Java web development.
For non Java files (JSP, CSS, JSF, JS etc.) you should see the changes instantly. For Java files, the plugin will reload the application to reflect the changed classes. While this works okay for small applications, for large applications the reload time can become significant. There can also be issues with permgen after multiple reloads and you can lose your session and be booted back to some previous screen and have to step back through the various screens to see your changes.
The ultimate solution then is to use a tool called JRebel which will swap you updated classes into the running VM without the requirement to reload the whole application as well as publishing non java files, reloading application config files (log4J, Spring) managing JPA entities and a lot more.
http://zeroturnaround.com/software/jrebel/
It's a commercial product and while not exactly cheap, in my experience worth every penny. I've been using it for years and couldn't live without it. Your productivity will increase x-fold especially when working on larger applications. No connection, just a satisfied customer.
For a free alternative see:
http://www.hotswapagent.org
In my experience, the tomcat plugin in eclipse has been flaky like this from the beginning. I suggest that you not use it - its just not worth the trouble.
There are at least two alternatives.
First, you could just install tomcat locally, build your war file, and deploy it manually.
A better alternative IMHO is to set up a maven build for your project, and then install the maven tomcat plugin, which just works. I've never seen it get flaky.
Something similar is probably available for gradle, if you want to use that instead of maven.
I've discovered that selecting Build Automatically, under the Projects menu item, changes in the code are automatically recompiled and added to the currently running Tomcat server instance.
Now it's going great! Much faster!

java development and redeployment

I used playframework previously. Development with play! is so fast. It has an internal java compiler and all the actlon methods are static. So the result is awesome.
Nowadays i use spring on netbeans. Netbeans has a deploy on save feature. But redeployment time is greater than 10 seconds. I used jrebel. But jrebel does not give the same effect. I used eclipse. Eclipse is worst than netbeans. Why java development should be so difficult? Is there any method for fast redeployment?
You have already mentioned JRebel. There are other options, but they are not faster. For example, WTP plugin for Eclipse. You can use jetty-maven plugin, you can use emended jetty-server for development. You can use file-sync plugin for Eclipse. This is 3 most popular and fastest way to deploy project. But all of them require redeploy of server.
You will never get this speed like Play framework or some dynamic compiler language. But probably it's not necessary ?
If you change static resources, like jsp, js, css, you don't need deploy. If you change Java code, just test your code with JUnit or something else. Or write a bunch of code and make deploy
IMHO the more experience you gain, rarely you make deploy =) You don't need to check, what's going on, because you know exactly, what you are doing =)
The reason why Play deployment is so fast, is that it isn't an actual deployment in the original sense of the word. Play checks for the modifications in your Java code, then takes just that file and compiles it and changes the state of the JVM to incorporate the new class.
A real deployment to an application server or event to "just" a servlet container is more than that. The package (war, ear) has to be expanded. Internal structures of the app server has to be updated and the app has to be started. This all takes time because much more components are working together.

Java web development environment to minimize build-deploy-test cycle time?

What Java web development environment is the best for absolutely minimizing the build-deploy-test cycle time?
Web development environment: JBOSS, Tomcat, Jetty? Deploy WAR exploded? Copy WAR or use symbolic links? There are factors here I don't know about.
Build-deploy-test cycle? The amount of time it takes to test a change in the browser after making a change to the source code or other resources (including Java source, HTML, JSP, JS, images, etc.).
I am looking to speed up my development by reducing the amount of time I spend watching Ant builds and J2EE containers start. I want the Ruby on Rails experience --- or as close as I can get.
I'd prefer a solution that is web framework agnostic, however if a particular framework is particularly advantageous, then I'd like to hear about it.
Assume all the standard tools are in use: Hibernate, Spring, JMS, etc. If stubbing/mocking support infrastructure is required to make this work, I'm OK with that. In fact, I'm OK with having a development environment that is very different from our production environment if it saves me enough time.
You should probably take a look at Javarebel:
http://www.zeroturnaround.com/javarebel/
and this thread here:
How to improve productivity when developing Java EE based web applications
JBOSS uses Tomcat for its servlet/JSP engine, so that's a wash.
Tomcat does support hot deploy.
Jetty's pretty small and starts quickly, but it doesn't support hot deploy.
Eclipse is merely an IDE. It needs a servlet/JSP engine of some kind. If it's like IntelliJ, you can use any Java EE app server or servlet/JSP engine you'd like.
IntelliJ is pretty darned fast, and you don't have to stop and start the server every time you rebuild. It works off the exploded WAR, so things happen fast.
Building (used to be compiling) is a a sign of our times. We need quick validation of our thoughts and our actions. Whenever I find myself building to many times it is usually a sign that I'm not focused. That I don't have a plan. For me this is the time to stop and think. Do a list of things that need to be done (this is web framework agnostic) do them all and test them all after one build.
Jboss Seam together with the Jboss Developer Studio is good for hot deploying everything aside from EJBs (SLSB, SFSB and Entities need redeploy).
Have you considered Grails?
Deployment is as fast as it can get with Google App-Engine + GWT (optional) + Eclipse Plugin.
Never seen anything faster.
Maven 2 and eclipse. mvn eclipse:eclipse <- pure awesomeness. Also, WTP within eclipse works great (and maven generates working WTP projects).
Small web containers will load faster than overloaded webcontainers with the kitchen sink built in (.. cough .. jboss ).
Some design decisions slow build times (e.g. aspect-weaving based toolkits add an aspect-weaving phase to compile times).
Avoid building components that can only be tested after long elaborate load cycles. Caches are a prime culprit here. If your system has deep dependencies on a global cache scattered everywhere you'll need to load the cache every time you need to test something.
Unit-testable components, so you can run pieces instead of the whole thing.
I find that projects built reasonably compile, deploy, and startup in a few to 10 seconds, which is usually fine.
GWT in eclipse is probably the fastest I can think of. Using the hosted mode browser for your tests you can debug and change your code without restarting anything. Just need to click the refresh button in the browser and the changes are there (java, css, etc). One other thing is that GWT is adding this same support to normal browsers (Firefox, IE, Safari) so you can debug from within them the same way. These changes are coming in 2.0. See http://code.google.com/events/io/sessions/GwtPreviewGoogleWebToolkit2.html
Have you tried using Eclipse Java EE and then tell it to deploy to a server managed by Eclipse? Tomcat and JBOss works pretty well in this way. Also allow you to change code in a method, use Ctrl-S and have the class updated inside the server.
MyEclipse also works pretty well like this.
JRuby on Rails. Develop on whatever platform you want, deploy to standard Java servers.
I think the best way to avoid the long build deploy tests cycles is writing unit tests for your code. This way you can find bugs without waiting for the build/deploy phases.
For JSP you can edit the JSP files directly in the JBOSS work folder:
> cd $JBOSS_HOME/server/default/tmp
> find -name myJspFile.jsp
./tmp/vfs/automountd798af2a1b44fc64/Jee6Demo.war-bafecc49fc594b00/myJspFile.jsp
If you edit the file in the tmp folder you can test your changes just hitting the browser refresh button.

Categories