How can you pack a GWT module as a Jar file with Maven?

I need to configure Maven to:

a) compile the GWT module

b) copy the * .java files in the bank (so that they can be imported into another GWT module)

c) copy the result of the compilation step in the bank (so that it can be used on the server as is)

Does anyone know how to do this?

The main idea is that I want to separate the GWT project from my Spring MVC project and remove any dependencies that the Spring application may have in the banks and GWT plugins.

This way I can use GWT modules as pure javascript libraries and load them with org.springframework.js.resource.ResourceServlet directly from Jar files, while maintaining the flexibility of reusing modules in other GWT projects.

Any help would be appreciated.

+4
source share
1 answer

I am attaching a solution that I came up with so that others can use it:

<!-- Set the output directory to something gwt:run can use in hosted mode --> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory> <finalName>gwt-build-name</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>${gwt.version}</version> <executions> <execution> <goals> <goal>compile</goal> <goal>test</goal> </goals> </execution> </executions> <configuration> <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp> </configuration> </plugin> <!-- Attach the resources plugin to the prepare-package phase to include the host page & generated javascript files --> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>package-generated-javascript</id> <phase>prepare-package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <!-- shove everything the compiler produced into the JAR/META-INF/ folder so that Spring resourceServlet can find it --> <outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory> <resources> <resource> <directory>${project.build.directory}/${project.build.finalName}</directory> <includes> <include>org.yournamehere.Main/**</include> </includes> </resource> </resources> </configuration> </execution> <execution> <id>include-host-page</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory> <resources> <resource> <directory>${basedir}/src/main/webapp</directory> <includes> <include>**</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> 

What this does is change the output directory to target / finalName so that everything ends in the same directory and attaches the resource plugin to the compilation, preparation-package steps to copy the output of the GWT compiler to the assembly directory. Once everything is there, it will default to the final bank.

Thus, the build directory contains everything that is required for the hosting mode, and all Spring servlet resources must serve the GWT module without any direct dependencies with the GWT.

+2
source

All Articles