admin管理员组

文章数量:1279175

I am currently working on migrating my standalone GXT 4.2 application to a Maven-based setup. My standalone application does not follow the typical GXT project structure with client and shared folders. However, the Maven-based approach requires these folders, and I am unsure how to restructure my project properly.

Current Standalone Directory Structure: /my-gxt-app
├── src/
│ ├── com/myapp/MainApp.java
├── lib/
├── war/
│ ├── WEB-INF/
│ ├── index.html
├── build.xml (used for Ant builds)

Target Maven-Based Directory Structure: migration-app
|── com/myapp/client/MainApp.java
├── com/myapp/served

├── com/myapp/shared

├── pom.xml (for Maven build)

How should I restructure my existing Java files into the client and shared folders in Maven?

I am currently working on migrating my standalone GXT 4.2 application to a Maven-based setup. My standalone application does not follow the typical GXT project structure with client and shared folders. However, the Maven-based approach requires these folders, and I am unsure how to restructure my project properly.

Current Standalone Directory Structure: /my-gxt-app
├── src/
│ ├── com/myapp/MainApp.java
├── lib/
├── war/
│ ├── WEB-INF/
│ ├── index.html
├── build.xml (used for Ant builds)

Target Maven-Based Directory Structure: migration-app
|── com/myapp/client/MainApp.java
├── com/myapp/served

├── com/myapp/shared

├── pom.xml (for Maven build)

How should I restructure my existing Java files into the client and shared folders in Maven?

Share Improve this question asked Feb 24 at 11:54 shaeshae 5173 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Maven-based projects do not require a client vs shared vs server split - but it is a very good idea, as it will help prevent some classes of errors, improve compiler/devmode performance, and simplify configuration. I don't advise doing these two migrations at the same time, but one and then the other, to avoid blaming the wrong migration for any issues that arise.

With that said, the "target Maven-based directory structure" is not splitting the classpaths, and is also not the conventional maven structure.

First, conventional maven structure includes uses "src/main/java" to hold your production Java sources (whereas "src/test/java" would include unit tests, "src/main/resources" would included non-java resources for the project, etc). Your war/ contents are also not included above - in a war project, that would fall under "src/main/webapp".

migrated-app
 - src/
   - main/
     - java/
       - com/myapp/...
     - webapp/
       - WEB-INF/
         - web.xml
       - index.html
 - pom.xml

Add tests and resources as necessary.

Next, breaking down the classpath so that you have three distinct maven projects, under a root project that contains them and builds them. This allows browser-only code to live in a client classpath, server/jvm-only code to live in a server classpath, and anything those two share to live in a "shared" classpath. Client and server depend on shared, allowing the compiler to notify you when a "shared" class is actually not truly shared (depends on either client or server code), or when some actually-shared class accidentally ends up living among either client-only or server-only sources.

Additionally, "server" depends on the compiled JS sources from "client", but not the .class files or any dependencies.

migrated-app-parent/
 - client/
   - src/
     - src/main/java/com/myapp/client/...
   - pom.xml
 - shared/
   - src/main/java/com/myapp/shared/
     - MyService.java
     - MyServiceAsync.java
     - MyDto.java
   - pom.xml
 - server/
   - src/
     - main/
       - java/
         - com/myapp/server/MyServiceImpl.java
       - webapp/
         - WEB-INF/
           - web.xml
         - index.html
   - pom.xml
 - pom.xml

See the modular-webapp archetype at https://github/tbroyer/gwt-maven-archetypes for an example generating this structure that you can follow.


In your place, I would attempt to first split the ant source directories and classpaths as possible, so that you fully understand the breakdown in the context of the tools you already use on a daily basis. Then, splitting to use Maven should be clearer.

Or, if you already understand Maven well but are adopting an Ant project that you aren't fully familiar with, go ahead and switch to Maven first without any package or project refactoring/renaming. This will very likely require some extra configuration of the gwt-maven-plugin (e.g. you won't be able to set packaging=gwt-app, and will likely need to continue to use a regular .gwt.xml file among your java sources (or in resources).

Either way, as soon as the project builds and runs at all, take the next step to complete the migration, so that it doesn't get put off until later, and you can take full advantage of your updated configuration.

本文标签: gwtMigrating my standalone GXT 42 application to a Mavenbased GXT 42 projectStack Overflow