0

Spring IO jar with embedded container fits like a glove with AngularJS as a UI. You can gunsling your static resources trivially with jar based spring io project (namely .html pages with angularjs or anyother javascript library).

For angular based front end SpringIO Web is really a perfect fit.

However, on the topic of having SpringIO packaged as a jar (not as a WAR) to cooperate with GWT built by maven, the problem seems to not be so easily solvable.

The only relevant answer on this topic so far is the following. Spring Boot + GWT embedded configuraiton

Indeed, if you were to just need to build a GWT application into a springIO jar (a productive jar), then one could live with simply making sure that the GWT javascript would fall into the appropraite META-INF/resources to be served to the client.

However, during development time when Java to Javascript compilation has yet to take place, and traditional the gwt:run plugin is used, it would be interesting to get an official response as to how a pom.xml should be properly setup so that:

(a) we use the embedded container of our choice tomcat or jetty

(b) during development time we get the benefit of container restart with the springio devtools. This works like a charm for Spring x Angular based programs where javascript resources are immidiately refreshed without a restar and class changes lead to a restart

(c) Still get to debug a GWT application without having to compile the full monster

I am wondering: Is the only way that person can develop productively using GWT and Spring IO at the same time is to state: - I need two containers. A front end jetty to run the GWT part along and serve the javascript and debug the front ent.

A back end application in spring IO where I have no javascript but can productively get my springboot dev tool to class change tomcat restarts.

and between the jetty and the embedded tomcat, integrate the two JVM containers using simple rest based web services. The Network cost is essentially redudant if both are on the same localhost. But, it is not a perfect world if to develop productively one would need a separate container that has GWT javascript and container that has the SpringIO business logic.

Would it be possible for springio to provie a GWT maven pom.xml so that one can work productively together using both GWT and SpringIO?

On my side, I must say I do not like the SpringIO WAr approach for which there is already a git project to demonstrate.

If the JAR SpringIO JAR with embedded container cannot be setup to lead to a productive development environment, I simply opt for two containers with the most effective development pom.xml for GWT fornt-end and busienss logic on springio backend. Many thanks for a reply on this.

Community
  • 1
  • 1
99Sono
  • 3,554
  • 27
  • 39

3 Answers3

2

You can easily run the SuperDevMode codeserver as a standalone application and it will recompile when you change anything in your GWT code (basically you end up with two containers: spring boot and the codeserver).
If you specify the launchDir to be where Spring Boot's looks up its static web resources, you just need to refresh the page to get a recompile. Otherwise you can always use the boormarklet to manually initiate a re-compile.

I would recommend to use Thomas Broyer's gwt-maven-plugin

Ümit
  • 17,379
  • 7
  • 55
  • 74
  • I do not follow completely your reply. Essentially it sound like your GWT configuration is identical to the one you get out of the GWT sdk that packages the app as a war. When you use the core pom of the GWT SDK you do mvn war:exploded and mvn gwt:run, and indeed you get the nice refresh feature working out of the box. But if you now add spring boot dependencies into such a pom: (a) your pom is a WAR pom not a jar pom. (b) Spring boot will fire up an abitrary embedded container jetty or tomcat depending on the cpath. So how exactly do you reconsile the gwt:run with the spring boot application? – 99Sono Jan 09 '16 at 10:31
  • My point,at the end of the post was precisely that: (a) if you use the gwt sdk base pom to configure your front'end container and (b) use spring'boot executable jar with embedded container, You get get 4 free 2 highly dev friendly poms. You can change your front'end and back.end code and have minimal configuration. It is preferable to integrate two contianers through cheap JAXRS API than have a single pom.xml setup for an application that is not development firendly. – 99Sono Jan 09 '16 at 10:49
  • I am not saying to put everything in one pom. Best practicse is actually to have 3 separate maven modules: client, shared and server (see also this [archetype](https://github.com/tbroyer/gwt-maven-archetypes)). The server will contain the configuration for spring boot, the shared is for shared assets and the client is the GWT one. – Ümit Jan 09 '16 at 11:38
  • Well, even if you create a Root Pom with dependency management, and then three child modules for server, shared and client, ultimately the client pom will have to gwt run Jetty to server the UI artifacts to the browser. And then the question is, how do you juggle it all? The client artifacts will update just fine with a browser refresh if you edit them. The server side artifacts of spring'boot are they being run by the gwt:run jetty? Or on their own "springboot:run" embedded container? – 99Sono Jan 09 '16 at 16:39
  • The server side artefacts are run by springboot:run. I have a similar setup with a traditional Spring app and GWT. I first run the codeserver for the client artefacts and then start mvn jetty:run to run the Spring app. I can update the server side code by using IntelliJ hot reload/JRebel or whatever and the codeserver will re-compile when I change something in the GWT code. Works just fine. – Ümit Jan 09 '16 at 16:59
  • Ah! Exactly, so the most productive way to work with GWT and spring boot, in your opinion is precisely to let the GWT jetty triggered by gwt:run manage the client side artifacts and on the back-end let the springboot tomcat/jetty handle the server side code. That was my impression as well... Essentially let the base pom.xml given GWT SDK and pom.xml produced by Spring IO manage each its main responsibility. That's fine for me. Thanks for the feedback. – 99Sono Jan 10 '16 at 14:25
0

In company where I work, we work with SmartGWT framework that is based on GWT. With this framework, we are easily integrated Spring on our project and you can easily debug/run project on SuperDevMode.

Marko
  • 45
  • 2
  • 6
  • Use spring with GWT is a given, if you are the one doing the configuration by hand or xml. The point is not configuring spring until the default configurations by spring boot are not to your needs. Spring boot is a development acelerator for spring. If you take charge of 100% of the spring configuration, sure... But then in your case, you are most likely building a war file, not the nice executable jar of springboot. Your probably also using Jrebel to put in place code changes in the back-end, spring boot gives similar development candy out of the box. – 99Sono Jan 09 '16 at 10:38
0

Proof of concept is:

Step (1) use gwt 2.7 web app creator to generate a sample gwt project with a proper pom. In this case doing a gwt:run already gives an OK development environment as far as seing client code refreshed upon change. Not bad but not enough.

Step (2) as proof of concept for spring boot dev tools server side refresh, go conservative and just add the jetty plugin to the pom. The jetty plugin gives you JRebel like configuration options that the GWT plugin lacks, even though it uses jetty. The GWT plugin does not allow you to express a scan interval for your classpath, whereas jetty does.

 <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.3.0.v20150612</version>
      <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <webApp>
              <contextPath>/</contextPath>
          </webApp>
      </configuration>
  </plugin>

Step (3) as hinted by Umit, one is not forced to run gwt with the embedded container during development time. Instead, one can work just as productively doing something of the form: mvn war:exploded mvn jetty:run-exploded mvn gwt:gwt-codeserver

This is rather ideal, as to update code changes on the UI one can use the code server bookmark to trigger a recompilation. And for the server side core jrebel behavior, simply mvn exploded:war when code changes, or fix you mvn build output directory to go into the WEB-INF/classes ... anyway, and jetty will pikcup the file changes and restart web app class loader quickly.

The same principle has to work with Springboot...

And indeed it does.

When using GWT+SpringBoot as a JAR the trick is two fold:

(a) just like when using our own jetty:run-exploded instead of the jetty of gwt:run embedded jetty; the gwt plugin needs to be tuned to have

<noServer>true</noServer>

(b) The gwt plugin assumes you will package the APP as a war, which is not the case. Thefore, to make sure that the springboot app serves your nocache.js file, you must make sure you tune the gwt plugin with somehting of the form:

<webappDirectory>${project.build.directory}/classes/META-INF/resources</webappDirectory>

The line above is a matter of taste. Spring boot supports several folders for static resources, I simply use the same folder you would dump four JSF libraries inside of JSF components jar file in a JEE app.

In any case, it is clear the plugins for springboot and gwt are not well married together, but together both maven plugins give us enough configuration options to make the thing work out properly during development.

As for production mode, it is obvious it works, it is just a matter of packaging the resources into the right folders before geting the final jar assembled.

In the end, springboot + gwt works fine, with UI source reloading as well as back end fast class reloading, without being forced to deal with eclipse tailored plugins, maven takes well care of everything. Perfect match for Netbeans.

99Sono
  • 3,554
  • 27
  • 39