Cascading GWT Application ?

358 views
Skip to first unread message

Pierre Mineaud

unread,
Jul 5, 2016, 6:09:04 AM7/5/16
to GWT Users
Hey.

My question is simple : is this possible of calling a gwt application into another gwt application.

My sample case is simplest as hell, but I can't figure it out what is the best solution to do it :
I Would like 3 differents GWT project to deploy them independently :
- A first app doing single job (App1)
- Another one doing other stuffs (App2)
- And a sophisticate menu to switch from the first to the other. (AppMenu)

Actually, what i am trying to do is using jsp file in App1 / App2 project to import the jsp file of my AppMenu. (Using c:import url="localhost:8080/AppMenu/AppMenu.jsp" />)
But when I do that, even if my AppMenu.jsp is rendering well my menu on my tomcat's url : localhost:8080/AppMenu/AppMenu.jsp, on App1's url I got nothing. The hearder and the simple html is printed in my page, but my GWT containerDiv is still empty.

I'm pretty sure GWT can do that, but i do not want create GWT module for each project to import a .jar in another. The goal is really to got 3 linked applications working together but independent ! 

Pierre Mineaud

unread,
Jul 5, 2016, 8:34:15 AM7/5/16
to GWT Users
I'm asking myself, is maven can help me ? 

Jens

unread,
Jul 5, 2016, 11:55:49 AM7/5/16
to GWT Users

I'm asking myself, is maven can help me ? 

No. Most likely something is wrong with your general approach. Check your browsers DevTools if all <script> tags for your apps are in the HTML and if they download correctly or if there are any errors on browser console / networking tab.

-- J. 

Gilberto

unread,
Jul 5, 2016, 1:36:46 PM7/5/16
to GWT Users
Hi again Pierre,

In my experience, having to manage two or more separate GWT applications can be really cumbersome. I'd recommend it only in cases where you have explicitly two or more independent products. In cases where you allow the user to switch from one app to other, or you have a large shared codebase among the apps, I suggest to consider unifying the apps into a single one, and manage the pages and URLs by using a framework for that (Activities and Places, GWTP and gwt-views are some examples of such frameworks).

But of course all depends on your specific use cases. In my case I had three GWT applications that was part of a larger product. After years maintaining those three separate applications, I decided it was better to just unify them all and fix the user navigation problems (when you have more than one application, the state of the app is not shared among other applications - assuming a stateless server - so when the user switches over apps, the state is lost, and that can hurt the UX).

About the maven stuff, it can really help you if you decide to split not only the GWT modules, but the Java projects as well. If you have, for instance, 3 GWT modules within 3 Java projetcs, maven can help you manage the dependency chain among the projects. But if you decide to use a single project (with or without multiple GWT modules), maven won't help as much.

Pierre Mineaud

unread,
Jul 7, 2016, 5:16:58 AM7/7/16
to GWT Users
Hi Gilberto and thanks for your experience return. 
I'm a litle bit sad about it, cause our wish was to deploy each application dependently, into different .war file on our tomcat server. 
I will get a look on your cited framework, maybe a good module architecture development can be enough for our need.

Pierre Mineaud

unread,
Jul 8, 2016, 5:24:01 AM7/8/16
to GWT Users
I accepted to stop searching how to get multi deployment for my application and working only with module in external project and getting one .war. It actually works great except one thing : the RPC.

I wouldn't to abuse about your help but here is what I done :
I created two applications with GreetingSampleGenerationCode. One playing the main application role and another playing the module role.
In my main application's project, I added in the java build path my module project. I also added in my main application's gwt.xml the inherits of my module.
When I launched my main application, I see my both greetingSample loading ! When I click on the first button I got the server's answer. Perfect ! But when I click on the second button I got an RPC failure.

Here is the exception (not sure the full stacktrace will help you more ^^) : 
An IncompatibleRemoteServiceException was thrown while processing this call.
com
.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. ( Blocked attempt to access interface 'garandeau.gwt.it7.module.toto.client.GreetingService', which is not implemented by 'garandeau.gwt.it7.main.server.GreetingServiceImpl'; this is either misconfiguration or a hack attempt )
 at com
.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:254)

I think the problem is a url path problem to access my servlet in my main app.
I tried so to add my servlet like this in my main application's web.xml (toto is my module's name)
<servlet>
   
<servlet-name>greetServlet2</servlet-name>
   
<servlet-class>garandeau.gwt.it7.module.toto.server.GreetingServiceImpl</servlet-class>
 
</servlet>
 
 
<servlet-mapping>
   
<servlet-name>greetServlet2</servlet-name>
   
<url-pattern>/toto/greet</url-pattern>
 
</servlet-mapping>

I'm pretty not sure about this /toto/greet as mapping, but I don't know what write better here
I tried to add the path in my module's descriptor as follow :
<servlet path="/toto" class="garandeau.gwt.it7.module.toto.server.GreetingServiceImpl" />

But same... 
What did I missed ?
Thanks for tips

Gilberto

unread,
Jul 8, 2016, 1:04:54 PM7/8/16
to GWT Users
Since you're building a new application with GWT, I strongly suggest you not to use GWT RPC. Take a look at this thread about the subject.

Take a look at the RestyGWT project. You still have type-safe communication with the server, but using REST instead of the proprietary GWT RPC mechanism. It's pretty simple to use and you won't miss RPC once you get used to it. The ideal point to start using it is at the beginning of the project, because porting away from RPC can be slow and painful if you build an entire application on top of it.

Pierre Mineaud

unread,
Jul 11, 2016, 11:19:28 AM7/11/16
to GWT Users
Thanks again Gilberto.

I followed your recommendation but the GWT world is pretty hard at the moment.
I followed the Ronan Quillevere's tutorial, but... like all GWT / maven / gradle / RPC / Vaadin etc... tutorials... nothing happened like it should in the tutorial ! 

I started to regive a try to maven... After a litle bit more experience with GWT, I thought it could be fine :) So I followed the tutorial until when I should use jersey to get a server's response by my url. But there, the only thing I got is an 404 error page. So i tried to use a localtomcat or a google app engine to get the job done, but still ! 
So I tried to do the same thing with a Dynamic Web Project by following the vogella's tutorial. And by importing the jars in my build path it worked... I tried though to import some jar in my maven project, but it is apparently impossible to do (I got an error with blank line in my Eclipse). I went then on the jersey download's page to get the last dependencies line, but now my page 404 is a 503 with that error : "org.eclipse.jetty.servlet.ServletHolder$1: java.lang.IllegalStateException: No generator was provided and there is no default generator registered". It is apparently theses package missing, but I can't import them in my project : 
hk2-api-*.jar
hk2
-locator-*.jar
hk2
-utils-*.jar
javax
-inject-*.jar
jersey
-guava-*.jar


Honestly, my GWT excitement I was there is 2 weeks ago is already gone. Everything I tried to do is, either impossible or deprecated / unadvised, neither So hard to do or really hidden. You asked me there is 2 weeks my first impression about GWT and why I gone on this technology, now I can tell you my short GWT experience is really rude and so vast than it is really hard to find what you are searching about... 

Thomas Broyer

unread,
Jul 11, 2016, 11:46:45 AM7/11/16
to GWT Users
First, define your overall architecture, knowing the platform you're building on/for (the web, HTTP, browsers, JS, etc.)
Then choose your technology stack, or assess whether and how they match your architecture.
Understand what each part does, then assemble things together.
Get things working one at a time, checking them separately (using cURL to test and debug your web APIs, your browser to test and debug your client app, not forgetting the browser's devtools' "network" tab to debug requests made to the server.

Gilberto

unread,
Jul 11, 2016, 1:10:50 PM7/11/16
to GWT Users
I see. Believe me it's not your fault. GWT is a mature technology, and there are tons of articles and tutorials that were written for different versions in different contexts, and it's hard to know which one is more accurate, mainly when you're starting with the technology.

I use Eclipse too, and sometimes Eclipse really mess the things up when dealing with different plugins at same time (in this case, GWT and Maven plugins). I'm used to it, but it took some time to understand the nuances of working with GWT on it.

Before you start, you have to think about 2 parallel dependency trees: Maven's and GWT's.

GWT have its own way to define which modules should be compiled and which module depends on which one. That's your Module.gwt.xml. On top of that there is which libraries you need to compile the Java project (now including not only the client side, but server as well). That's where Maven comes in.

The thing is, you can create a GWT project without Maven. You can import all the jars you need by hand if you prefer. Or use another build tool. Its your choice. But you can't get rid of you Module.gwt.xml.

So let's start by it. Paste you Module.gwt.xml here so we can take a look at it and see if there's something wrong =)

Since you're new to GWT and Maven, I'd say it's a good strategy to make GWT work alone before entering in the Maven world.

Pierre Mineaud

unread,
Jul 12, 2016, 6:20:57 AM7/12/16
to GWT Users
Thanks for your answers and many thanks again for the helps and advices ! 
@Thomas : This is what I've done. I try to go slowly to understand it all. So here is my wish list : 
- Getting an modulable application, and possibly separate each modules in different projects to clarify the code.
- Calling all theses modules in a single page
- Being able to communicate with server for each module and retrieving data "everywhere"

Like you said, I firstly try to masterise a litle bit more gwt before to add maven things in my project, even if I understand well where and how it can help me now.

@Gilberto : Many thanks for your help offer and here is a Git repository of my last try, I didn't package all projects in an initial workspace and I didn't commit my test : https://github.com/Manovsky/gwtModuleWorkspace

Some explication about it : 
it7_gwt is my main project. It is composed by : 
- the gwt sample 
- defining 3 div for my displayable module
- and an intraModule who is using jersey to be able to use restyGWT in the futur ;)

it7_menu is just a menu done in uiBinder and display itself in the divMenu

toto is a greeting sample by GWT plugin. I charge it in my main html page to try RPC by an external project module.

jerseyModule is the same module as intraModule to try the solution, again, to externalise my server communication.

The external resource is just a directory with all the needed jar. Cause I didn't manage to do the same all things with maven at the moment :)

And all this is rendering me a page with my 3 displayable modules (my menu on the left and my 2 greeting modules one of the top of the second), but the server call in RPC works on the it7_gwt module (popup show up and respond correctly) but the second (the toto one) is poping an error. 
And same thing with jersey. When I try to go on http://127.0.0.1:8888/rest/hello, my server respond an Hello Jersey page... fine... but on the http://127.0.0.1:8888/jersey/salut (who is the path in my web.xml / module jax-rs) i got an 404 page.

So at the moment, and like you said, all is working fine when you develop in a single project, but when I call module from external, I didn't manage to access to "their" servers.
Is this the problematic ? How should I do or how to architect the project / module in my project to get an clear thing ! 

Hope there will not have so much wrong things :D

Gilberto

unread,
Jul 12, 2016, 10:23:48 AM7/12/16
to GWT Users
I suggest these layouts:

Single Java project:

/src/main/java
   
/app1
        app1
.gwt.xml
       
/client
   
/app2
        app2
.gwt.xml
       
/client
   
/menu
        menu
.gwt.xml
       
/client
   
/commons
        commons
.gwt.xml
       
/client
       
/shared
   
/server

Explanation:

"App1" and "App2" are the two separate applications, which one in their own host page. They can be accessed independently. "Menu" is just another application with its own host page, but depends on "App1" and "App2". "Commons" is a lib project, in other words, not an application, but a collection of resources shared by all other projects. Put there any client or shared code that will be used by the other modules. "Server" is not a GWT Module, it's just a package with the server code and the business logic.

Since every module will depend on "Commons", anything you define on its gwt.xml file will be inherited by the other modules.

Multiple Java Projects:

/app1
    /
src/main/java/app1
        app1
.gwt.xml
       
/client

/app2
    /src/main/java/app2
        app2
.gwt.xml
       
/client


/menu
    /src/main/java/menu
        menu
.gwt.xml
       
/client

/commons
    /src/main/java/commons
        commons
.gwt.xml
       
/client
        /shared

/server
    /src/main/java/server


When using multiple Java projects you need not only to deal with the dependency among GWT modules but also the dependency among Java projects: "Menu" project will depend on "App1" and "App2", which will both depend on "Server", and "Server" will depend on "Commons". This way the dependency chain is formed, and there's where you put Maven to work.

This approach is better if you want separate artifacts/archives (.war) for each project. With each project in its own .war file you can deploy them on different servers at different locations. If you only need three different html pages within the same server, I suggest the single project layout.

Of course those are only suggestions. They assume that you have a single server code that can be accessed by any of the apps. If you need a separate server logic that only some of the apps should have access to, then you should create multiple server projects.

There are some threads talking about multiple module GWT projects you should read (if haven't already):

http://stackoverflow.com/questions/2274601/gwt-multiple-modules
https://groups.google.com/forum/#!topic/google-web-toolkit/DYVZj4WzjEU
https://groups.google.com/forum/#!topic/google-web-toolkit/wndMtcm4hR4

In general I suggest you not to mix multiple compiled modules (*.nocache.js) on the same HTML hosting page. If you need to mix two modules on the same page, create a third project that depends on both modules and create a single *.nocache.js for it.

If you want to go crazy you can put Maven modules in the mix (on top of GWT modules and Java projects), but for now you should focus on having a running project.

Hope it helps =)

--
Gilberto

Pierre Mineaud

unread,
Jul 12, 2016, 12:09:47 PM7/12/16
to GWT Users
Thanks a lot for your approach. I will give it a try deeper tomorrow. 
But just a simple question is coming to mine, you said to not mix compiled modules on the same HTML page, but I have to do it ! :) 
My menu must be on all my intranet page to navigate from anywhere on all other module. I can't create another project to get menu module + app module for each... right ? 
Did I must use a jsp menu instead of a GWT menu so ? 

Gilberto

unread,
Jul 12, 2016, 1:36:23 PM7/12/16
to GWT Users
In that case you can use iframes. Do you have an working example or knows a similar product that uses the workflow you're describing? Maybe looking at a live example I can give you better insights on how to organize your project.

Pierre Mineaud

unread,
Jul 13, 2016, 3:12:17 AM7/13/16
to GWT Users
The official GWT's example Ruxit is really looking at what I want to do. 
- A Menu always shown. On the left, on the top... who cares...
- An url changing when I change page
- An "Module Loader" on the right side of the page to charge my differents page.

I do not want using iframe cause I want to be able to log my user on this menu. That said I have to do some server / session works in that iframe and by my experience, there is always something wrong when using it.
To be honest, that's one of the reason we quit meteor :)

Pierre Mineaud

unread,
Aug 2, 2016, 4:43:56 AM8/2/16
to GWT Users
Hey there. 
I come back there to give you my final approach of this problem.

I create a Main Module who inherits of all my needed modules and specify my onlyone entry-point. It looks like that : 
<module rename-to='main'>

   
<inherits name='com.google.gwt.user.User' />
   
<inherits name='com.google.gwt.user.theme.clean.Clean' />

   
<inherits name='garandeau.gwt.it7.menunav.MenuNav'/>
   
<inherits name='garandeau.gwt.it7.module.app1.App1'/>
   
<inherits name='garandeau.gwt.it7.module.app2.App2'/>
   
<inherits name='garandeau.gwt.it7.module.app3.App3'/>

   
<inherits name='org.gwtbootstrap3.GwtBootstrap3' />
   
<inherits name='org.gwtbootstrap3.extras.animate.Animate' />
 
   
<entry-point class='garandeau.gwt.it7.main.client.Main' />
 
   
<public path='resource'>
       
<include name='css/*.css'/>
       
<include name='js/*.js'/>
   
</public>

   
<stylesheet src='css/bootstrap.cerulan.css'/>
 
 
<source path='client' />
 
<source path='shared' />

 
<add-linker name="xsiframe" />
</module>

Java side I manage my applications (modules) states and their history. It's a kind of router for all my webapp.
For that in my onModuleLoad I initialise my History.addValueChangeHandler function with all known states of my modules, then, and I charge them in a declared "divMain" div in my html with a public function like that :

public void chargeMainModule(String appName, String state) {
RootPanel.get("divMain").clear();

App1 app1;
App2 app2;

switch (appName) {
case "Init":
app1 = new App1();
app1.onModuleLoadByMain("divMain");
app2 = new App2();
app2.onModuleLoadByMain("divMain");
break;
case "App1":
 app1 = new App1();
app1.onModuleLoadByMain("divMain");    // The string argument is the div's name to charge the module.
addInUrl("mod", "App1", 0); // addInUrl is the main's function to manage a key and a value in the url at the specified lvl.
break;
case "App2":
app2 = new App2();
app2.onModuleLoadByMain("divMain");
addInUrl("mod", "App2", 0);
break;
default:
break;
}
}

Then, I create my other modules with their own inherits and without entry-point ! It's my main's chargeModule function who will trigger the code in my module.

- I externalise as well the RPC Call. So all my module got a pointer on my RPC project, and this one is collecting all the RPC client / server and shared code. It's usefull for deployment, enjoyable for developping to not recreate things already done etc... My servlet is put in my web.xml of my main by application route. Ex : /main/app1/greeting and this is pointed to my Implement class in my RPC project

- Common code, like connectLdap for example should so be placed in an other project (gwt module) called ExternalTools. This allow to use global class or function everywhere in my workspace.

- I create to finish a skeleton project who emulate my ldap login, using the RPC project and charge one module at once... so I can dev my module without using my main, but using the skeleton project, totally independently. Really useful for external development.


So my current project seems like : 
Main 
     |-- instanciate --> Menu (who get instance of main to launch chargeModule function with app and div argument)
     |-- instanciate --> App1 ----------- using --> RPC
     |-- instanciate --> App2 ----------- using --> RPC
     |                               |   
     |                   using if necessary  
     |                               |   
     |                              V
     |-- instanciate --> ExternalTools 

Skeleton (Using for dev)
     |-- instanciate --> App1 -- using --> RPC
     |                               |   
     |                   using if necessary  
     |                               |   
     |                              V  
     |-- instanciate --> ExternalTools 

For deployment, I have so only one .war, the only thing I have to do before uploading it on tomcat is to copy paste the class of my RPC project in my classes folder of my main's war. A easy bash is doing well the job.
So at the moment, all is working perfectly, my module loading and navigation is pretty fluid and clean and well separate. 

I given up on maven, who is complicating (in my opinion) all the works done. I gave a try to rest, but I found RPC easy enough at the moment for us, and it responsed well at our need ! 
If you have questions, observations or advices, I will be glad to read :)

PS : Sorry for my english, I wrote this post quickly and some terrible mistakes have should appears ! :D
Reply all
Reply to author
Forward
0 new messages