Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a GWT Maven project structure, that doesn't mix up responsibilities?

Tags:

java

maven

gwt

I am just getting started with GWT development using Maven as a build system.

I come from the Java + Flex world, so naturally I have client side modules and server side modules that are cleanly separated.

While digging into the best-practices og GWT and digging deeper and deeper, to me the default configuration of GWT projects feels more and more like a total mess of responsibilities. Especially when it comes to multi-module projects.

I did understand, that the convention states that server-side logic belongs in "server" packages, shared code in "shared" and stuff that is compiled to HTML+JavaScript by the GWT compiler in "client" packages. And all code goes to src/main/java. So far so good.

No matter how I try to see it ... to me stuff in the "client" packages is simply dead-code. Even if the java compiler compiles this to classes, the classes are never used at runtime and are only needed to provide input to the GWT compiler in the compilation phase. So even if it looks like Java, it's actually not and only looks like Java. It sort of feels dirty to place these inside the same jars as "live" code.

Wouldn't a maven structure like this make more sense:

/src/
/src/main/
/src/main/java
/src/main/shared
/src/main/gwt

And to have the java-compiler-plugin use src/main/java and src/main/shared and the GWT compiler to use src/main/gwt and src/main/shared?

Also it would feel a lot better if the build would produce two types of artifacts ... normal "jars" containing clases from src/main/java and src/main/shared and a second "gwt", which contains classes and sources of src/main/gwt and src/main/shared.

I wouldn't add a dependency to some mixed-up jar, but could decide if I want to import some GWT components or if I want to import some server-side functionality.

Next thing is that the GWT default is to place xml, resources and other stuff in src/main/java ... XML && Resources != Java ;-)

Or is there a real reason for all of this, that I simply haven't realized yet ... or do I simply have to start getting dirty and not worying about stuff like that?

Chris

like image 852
Christofer Dutz Avatar asked Feb 22 '13 10:02

Christofer Dutz


2 Answers

I came to the same conclusion a while ago, and created a couple archetypes to help get started: https://github.com/tbroyer/gwt-maven-archetypes (announcement).

Those archetype still have the *.gwt.xml et al. into src/main/java, because the Google Plugin for Eclipse didn't support putting them anywhere else (I've heard it's been fixed in a recent version but haven't checked yet).

like image 64
Thomas Broyer Avatar answered Nov 17 '22 15:11

Thomas Broyer


I have also tried to separate GWT client-side code from server-side code. The method I have used is to have a top-level project with 2 sub-projects, one for server-side, one for client-side. The top-level project has a pom.xml containing a element for each sub-project.

The client-side project contains GWT java source in src/main/java and the rest of the webapp files in src/main/webapp. The server-side project contains just the server-side code.

Probably not the tidiest solution but at least there's a clearer separation.

like image 3
NickJ Avatar answered Nov 17 '22 16:11

NickJ