Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

GWT Maven project Structure

80 views
Skip to first unread message

Ying Jin

unread,
Feb 5, 2025, 7:25:44 PMFeb 5
to GWT Users
Hello,

We have a big GWT project with following configurations that needs to be converted to a Maven  project. 

GWT2.9
JDK11
Eclipse 4.24
Tomcat 9

We have changed our project by applying the Maven folder structure as below, however, we're not sure if we need to separate the java files to Client/Server/Shared folders or not.

src/main/java -> java sources
src/main/resources -> resources: .properties files, .xml files, ...
src/test/java -> test java sources
src/test/resources -> test resources

According to the project structure specified by the following gwt maven archetype,  we need to move our java files by using this approach, is it correct? In other words, what is the best way to determine which files need to be put in the Client/Server/Shared folders?

https://github.com/xlavs/gwt-maven-archetype


Client folder:

/**
 * The client-side stub for the RPC service.
 */
@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    String greetServer(String name) throws IllegalArgumentException;
}

 * The async counterpart of <code>GreetingService</code>.
 */
public interface GreetingServiceAsync {
    void greetServer(String input, AsyncCallback<String> callback)
            throws IllegalArgumentException;
}


Service folder: 

 * The server-side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
        GreetingService {


As our project is a large one with many packages without clear separation, what is the best way to convert it to Maven project with proper structure in a timely manner? I read some posts suggesting to use a multi-module project structures for a big Maven project. Is it the right way to go? Or we have a simple way to convert it as we don't have much maven experiences for the multi-module project. 


Your help is much appreciated!

Jenny



Colin Alworth

unread,
Feb 5, 2025, 10:30:29 PMFeb 5
to GWT Users
Whether or not you "need" to separate into client/server/shared is really up to your team and your requirements. I would nearly always advise doing it, given the choice, but "need" is perhaps a little strong.

The linked https://github.com/xlavs/gwt-maven-archetype/ project doesn't appear to actually be broken up into separate classpaths, just separate packages. Again, given the choice, I would go further than this, breaking into separate projects, to isolate the client and server classpaths from one another. If you're putting effort into this, consider going a step further, and consider the "modular-webapp" archetype at https://github.com/tbroyer/gwt-maven-archetypes/ as a potential starting point. Besides being quite a bit newer (and supporting running on Java 11, etc), it also uses a better supported GWT maven plugin.

Separating your client/server/shared is almost always easier than it seems - after all, your JVM cannot run actual client code, and GWT+browser cannot run actual server code. The gray area is the code that both JVM and gwt+browser may be able to use many of your classes - especially beans that can be serialized over GWT-RPC. For projects with a long history, the lines often blur further, but the blurring is usually more to do with how many classes there are rather than how much actual overlap there is.

Your .gwt.xml file either has <source> tags in it, or uses the default of the "client" package. That alone will narrow things down - anything outside of those packages is exclusively "server", and anything in the GWT source packages is either "client" or "shared". Make that first cut, moving server-only code to one module, and either put everything else in "shared", or try to find a pretty clear divide of "probably-client" and "everything else" to put in shared. Get that to compile and run, and then work out where the lines really lies.

Another tool you have is the "-strict" or "-failOnError" flag to pass to the GWT compiler. That tells the compiler to fail if code doesn't compile, indicating that it either is actually server-only, or just dead code that can be removed.

Ying Jin

unread,
Feb 6, 2025, 11:09:00 PMFeb 6
to GWT Users
Colin, 

Thanks for your suggestions. We will consider the modular-webapp archetype approach later after we gain more experiences in maven and gwt integration.

Currently, I've followed the tutorial post below to learn more about maven and gwt integration process. 

No issue was found in the command line to run "mvn install" for this sample project, however, I encountered following error in Eclipse after I imported this project as a maven project though I can run "Maven install" command successfully in Eclipse. Therefore, I'd like to know how to get rid of this error or I can just ignore this error.

Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.2:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.2'. A required class is missing: Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer

-----------------------------------------------------

realm =    plugin>org.apache.maven.plugins:maven-war-plugin:2.2


Another question is if I can use Eclipse built in internal jetty server to start the super dev mode or not. I recalled that we have to use external tomcat server to run the project after we upgraded the jdk from jdk8 to jdk11 as the eclipse gwt plugin can no longer be used for newer version of jdk. What's your suggestion to deal with the following problem? I'll also do more research for this problem tomorrow.


[INFO]
[INFO] --- gwt-maven-plugin:1.0-rc-8:codeserver (default-cli) @ TodoList ---
[INFO] Turning off precompile in incremental mode.
[INFO] Super Dev Mode starting up
[INFO]    workDir: C:\Apps\JavaStudy\GWT2.9\gwt-2.9.0\TodoListApp\target\gwt\codeserver
[INFO]    [WARN] unable to delete 'C:\Apps\JavaStudy\GWT2.9\gwt-2.9.0\TodoListApp\target\gwt\codeserver\org.gwtproject.tutorial.TodoList\compile-1' (skipped)
[INFO]    [ERROR] unable to create directory: C:\Apps\JavaStudy\GWT2.9\gwt-2.9.0\TodoListApp\target\gwt\codeserver\org.gwtproject.tutorial.TodoList\compile-1
[WARNING] 2025-02-06 21:56:25.556:INFO::main: Logging initialized @847ms
[INFO]    Loading Java files in org.gwtproject.tutorial.TodoList.
[INFO]    Module setup completed in 1661 ms
[WARNING] 2025-02-06 21:56:26.818:INFO:oejs.Server:main: jetty-9.2.14.v20151106
[WARNING] 2025-02-06 21:56:26.837:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@7238072e{/,null,AVAILABLE}
[WARNING] 2025-02-06 21:56:26.846:WARN:oejuc.AbstractLifeCycle:main: FAILED ServerConnector@4de37f33{HTTP/1.1}{127.0.0.1:9876}: java.net.BindException: Address already in use: bind
[WARNING] java.net.BindException: Address already in use: bind
[WARNING] at java.base/sun.nio.ch.Net.bind0(Native Method)


Your help is much appreciated!

Jenny

Reply all
Reply to author
Forward
0 new messages