Best way to develop with Spring Boot + IntelliJ - spring

We've got a product that is built on top of Spring Boot and deployed via an executable war via embedded Tomcat, but during development we've adopted the approach of developing on a hosted Tomcat so our IDEs (IntelliJ mostly) will have hot-swap / redeploy support (rather than cycling our entire app, which takes a while to boot).
We recently added spring-boot-starter-websocket to our project & have run into issues with the hosted Tomcat's classloader using the embedded Tomcat's resources and crapping out. We can get around it by using profiles and marking the embedded libs as provided so that only our CI builds include them, but it's error prone & hacky at best.
So, my question is this: is there a better way of doing things? Using the Maven plugin or the runnable class introduces problems, as the maven plugin won't hotswap and the runnable class has issues finding classpath things like JSPs (wish we had switched to Thymeleaf beforehand, but next time ;)
The requirements for a "better" development cycle would be:
Code hotswap - aka not having to restart the app / server while developing (outside of making changes to method signatures & whatnot)
Good tooling support
Easy, repeatable setup -- pretty much "checkout and run"
Thanks!

You don't need tomcat for class reloading anymore. With Spring-boot 1.2 you can just debug the maven target spring-boot:run and have class reloading.
This works for me in intellij.

Related

GWT application deployed locally to Intellij Tomcat does not see breakpoints in gwt-aware client-module

Some facts about the application:
It consists of several modules, one of which is a GWT client module
Spring 3
GWT 2.6.1 (+ compatible GXT)
Is packaged as .war and can be deployed to a standalone Tomcat
Chrome add-on does not work anymore, so until recently I had to rely on Eclipse + embedded Jetty + Firefox 24 to be able to launch the app in DevMode and debug it
The other day I decided to try to launch it in IntelliJ IDEA and see if the debugging would work there.
Observations after deploying the app via a local Tomcat configuration in IntelliJ:
The app is deployed just fine (wither using war or exploded war artifact). Basically, Intellij takes the work directory from the standalone Tomcat installation and moves it into its installation folder (eg. .IntelliJIdea2019.1/system/Tomcat/Unnamed_MYAPP). Config files get also copied to the config dir.
The webapps dir of Tomcat stays within the original Tomcat installation and the app is deployed there
At first I thought the breakpoints are not recognized at all. However, it turned out that I was testing breaking only within the GWT client module; when I later tried some other module - the execution stopped as expected.
Now, what's interesting is that when I would develop and debug with Jetty, if I made a change to the GWT client-module, I could simply reload the page and it would appear.
With Intellij and Tomcat, it's the opposite. Breakpoints do not work as mentioned, but also refreshing, eg. via Update classes (instead of full redeployment) does not work, whereas for the other module it does.
Is there a way to somehow adjust my artifact so that GWT module as well can be debugged?
My exploded war artifact looks like this:
< output root >
META-INF
MANIFEST.MF
WEB-INF
classes
GWT module compile output
lib
web.xml
webapp directory contents
GWT client module GWT compiler output
Actually, it was a silly situation - I was expecting the execution to stop at the breakpoints set in the Java code of the gwt-aware module -- but since it was already transpiled to Javascript -- that was impossible.
The only way for breakpoints to stop in such a module is to use the DevMode.

How do I implement dynamic reloading in Spring (Netbeans)?

I'm used to writing Grails applications where my view or controller changes are automatically redeployed on save. I'm now stringing together a Spring Web-
MVC application and I'd like the same feature.
I'm using Netbeans as an IDE, Gradle as a build tool and the spring-boot plugin at the moment. I remember some talk of people using Jetty as it's so quick to restart that dynamic class reloading / deployment is no longer necessary. I've heard others mention JRebel which I used to use a few years back. I'm sure there is a more modern, spring-supported / spring-standard way of doing it.
I'd also like to know if you recommend deploying as a WAR or as a standalone executable JAR with a lightweight built-in web server.
Recommendations appreciated.
A yet unsolved challenge
It turns out that the Netbeans Gradle plugin does not support "compile on save" out-of-the box - and this means that a Java Agent won't be able to pick up the changes. The author kelemen suggested one or two approaches around this. It's a non-negotiable for me, so I decided to switch IDE's to Eclipse (terrible Gradle support), then IntelliJ Idea - which is looking very promising.
Netbeans Gradle Author Comment: https://github.com/kelemen/netbeans-gradle-project/issues/183
Alternatively, there is Jrebel, which is claimed to be able to support this Netbeans / Gradle combination. I wasn't able to get it working easily using a trial of JRebel. The JRebel support guys are there to help, so if you're willing to pay the price, it's likely that their support team will solve your problems.
JRebel: http://zeroturnaround.com/software/jrebel/
If anything changes, please comment below...
Spring class reloading is supported by HotswapAgent as well. It is free alternative to JRebel.
Spring has their own agent as well: https://github.com/spring-projects/spring-loaded. While developing why not just use embedded Tomcat/Jetty provided by Spring Boot.

Update dependencies while in hosted mode in GWT

I have a GWT webapp split into two Maven projects where one is a dependency to the other. Each time I change something in the dependency and I'm running webapp in hosted mode I have to rebuild the subproject and restart hosted mode for changes to apply. It takes a lot of time so I'd like to ask you if there is any way to make GWT using "live" version of the dependency?
There are 2 cases:
for server-side code, assuming you use the DevMode's embedded server, rebuilding the app and then refreshing the server should be enough
for client-side code, AFAICT, you have to use the source and output directories of the dependency module rather than the JAR containing them (GWT will load the source from the classpath, but apparently it'll only see the modified sources if it comes from a folder rather than a JAR; at least that's what I found in my tests). This goes against The Maven Way™ but the only solution so far is to use a special profile that will import the sources of the dependency project as sources of the project you're running. You can see examples of that in my archetypes.
There's actually a bug opened for the gwt-maven-plugin, MGWT-332, to do that automatically when running a reactor build. I also mused about what's really needed, for the forthcoming official gwt-maven-plugin (rewritten from scratch, independent from the CodeHaus Mojo plugin).
If your dependency does not come from a reactor build, then you're out on your own: you chose to make it totally distinct, so that's how it'll behave: you'll have to release it (even a snapshot) each time you make a change to it, and use the new version in your app (which means re-launching the DevMode).
This can be circumvented by running DevMode on your own, without the help of the gwt-maven-plugin. You're left on your own managing the classpath though (using the Google Plugin for Eclipse, I suppose you could simply edit the launch configuration to add the source folders of your dependency project to the classpath, before the classpath provided by Maven, that would reference the JAR).
Remove the dependent other application jar file from the primary application lib folder under webapp.
Eclipse should then resolve the dependency using the other project in the workspace if you have added it to your primary application classpath.
As GWT build takes ages, we invested some money in a JRebel license. We have two separate Eclipse projects for our back-end and our GWT front-end. JRebel reloads the classes automatically and I never need to restart my local server while writing code. It proved to be a wonderful time saver. Definitely worth the investment.

Play framework core classes externalized in maven module

I'm starting a new project development and for now I'm quite pleased and interested by what Play! 2.1 offers. So I'd like to use it for the main website and end-user experience. However I wouldn't want to be dependent on Play for the rest of the project. I'd like to be able to write the admin module with say GWT anytime and so on.
So I'm thinking to use Play! as a kind of a front-end for my application which I'd write using Spring framework, Hibernate and Maven. I'll then package it as jar and add it to play as a SBT dependency.
The problem is this: how do I setup the development environment so I'll have 2 projects: one for the core classes using maven and the other for the website using play so that whenever I change code in the core project I won't have to build and redeploy the jar files to an internal maven repo from where play would be reading them. How can I achieve this kind of a setup?
BTW I'm using IntelliJ IDEA if this matters.

Hard time on learning Java EE - mostly installing and testing stuff

Its quite a while since I started learning Java EE (I come from Rails world).
I'd like to test create a simple blog to test these:
- Hibernate, JPA
- Spring with MVC
- JSF and routing
- Struts 2
- Eclipse and local test (modify, reload, check changes)
- Tomcat, Jboss or Jetty
- An administration area (Session)
- Maven
I've a basic knowledge of each of those but as soon as I spend tons of time installing stuff and, somehow, I manage to resolve all inconveniences there is ALWAYS something that goes wrong (installation, tutorial obsolete, should I work with Spring IDE, MyEclipse, Jboss Application Server or regular Eclipse?, tons of random errors, each tutorial asking for random dependencies, each showcase).
QUESTION
How do you create quickly a startup project with these components?
You go with some Maven archetype? If so which one?
What I'd like is something I can download or build equipped out of the box with all above mentioned components. To name a few:
- railswizard.org, youvegotrails.com, railsboost.com/templates/new
SIDE QUESTION
Currently I'm following this great series, can you suggest some more like this:
- http://www.youtube.com/user/koushks?feature=gb_p13n_ch_rec
All the above components in a single project? That makes no sense; Spring MVC, Struts 2, and JSF would rarely be combined in the same project.
Each web framework has demo applications, what's wrong with those? There are archetypes for at least some combinations, although I'm not sure it's not better to put them together yourself.
Without knowing what kind of issues/errors you're getting, it's impossible to help. Maven should be taking care of most/all dependency issues. You shouldn't be spending much time installing anything by hand except maybe an app container.
IMO you're better off asking specific, actionable questions, and start with each specific technology and build up an application, rather than trying to integrate everything at once--a sure recipe for frustration.
For starting with a simple Java EE application, a good point to start is just downloading a Java EE 6 implementation.
Those are offered by various parties, which might be confusing at first. It's however just like there isn't the One and Only C compiler, but there are many and they all compile the same standard C.
For Java EE 6, obvious choices are GlassFish 3.1.2, JBoss AS 7.1, TomEE. (just pick one, at this stage it doesn't matter much which one you'll use).
Java EE 6 is a full stack solution. It's a single download and you don't necessarily need to install any other libraries. It comes with an MVC framework (JSF), an ORM solution (JPA), dependency injection (CDI), business logic support (EJB) and then some.
As for the IDE, NetBeans has a particular good default integration for GlassFish (can even be downloaded as one bundle), but for Eclipse it's not that difficult either. You need to download the Java EE edition of Eclipse and after starting it, go to Help -> Eclipse Marketplace, search for "GlassFish" and install the "GlassFish Server Plugin".
See also Minimal 3-tier Java EE app, without any XML config for a very minimal example to get started and JSF 2.0 tutorial with Eclipse and Glassfish for a very detailed one including instructions how to exactly setup the IDE.
What I'd like is something I can download or build equipped out of the box with all above mentioned components. To name a few:
http://appfuse.org/display/APF/Home
Appfuse will take you through the initial setup of a maven built spring based web application with hibernate included.
If you come from the rails world you might also look into Spring Roo which tries to borrow from Ruby i'm told. The primary focus of roo is to stand up all of the technology you've listed above quickly.

Resources