Plugin Maven GWT : Différence entre versions
m |
(Aucune différence)
|
Version actuelle en date du 27 octobre 2016 à 14:05
Ce plugin permet de construire des projets GWT depuis des commandes Maven.
Sommaire
Votre avis
Nobody voted on this yet
|
|
Création projet avec archetype:generate
Exécution
Le moyen le plus simple de créer un projet GWT est d'utiliser la commande archetype:generate
avec maven, en spécifiant les arguments:
- archetypeGroupId: org.codehaus.mojo
- DarchetypeArtifactId: gwt-maven-plugin
- DarchetypeVersion: 2.4.0
- DgroupId: myGroupId
- DartifactId: myArtifactId
Un projet avec le groupId myGroupId
et l'identifiant d'artifact myArtifactId
sear alors créé. Lors de l'écriture de cet article, l'utilisation de la commande, une erreur était levée concernant le numéro de version du plugin maven-archetype-plugin
. Pour y remédier, un fichier pom.xml
a été créé, en forçant la version de ce plugin
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Project Information -->
<artifactId>gwtStudy</artifactId>
<description/>
<groupId>fr.ejn.tutorial</groupId>
<name>GWT with Maven pugin</name>
<packaging>pom</packaging>
<version>1.0</version>
<build>
<!-- Force the archetype plugin for maven, for archetype creation. -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
<properties>
<!-- Use a custom version of GXT. Do not forget to upload the artifact into a server like Nexus. -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- GWT only works with 1.6 -->
<maven.compile.source>1.6</maven.compile.source>
<maven.compile.target>1.6</maven.compile.target>
</properties>
</project>
Ainsi, le projet peut être créé sans erreur. Lors de la construction, il est demandé de spécifier la version (par défaut 1.0-SNAPSHOT), le nom du module (du fait de la présence du pom parent) et de confirmer les paramétrages.
#mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.4.0 -DgroupId=fr.ejn.tutorial -DartifactId=gwtArtefact [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building GWT with Maven pugin [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] [archetype:generate {execution: default-cli}] [INFO] Generating project in Interactive mode [INFO] Archetype repository missing. Using the one from [org.codehaus.mojo:gwt-maven-plugin:2.4.0] found in catalog remote [INFO] Using property: groupId = fr.ejn.tutorial [INFO] Using property: artifactId = gwtArtefact Define value for property 'version': 1.0-SNAPSHOT: 1.0 [INFO] Using property: package = fr.ejn.tutorial Define value for property 'module': : gwtArtefact Confirm properties configuration: groupId: fr.ejn.tutorial artifactId: gwtArtefact version: 1.0 package: fr.ejn.tutorial module: gwtArtefact Y: Y [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: gwt-maven-plugin:2.4.0 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: fr.ejn.tutorial [INFO] Parameter: artifactId, Value: gwtArtefact [INFO] Parameter: version, Value: 1.0 [INFO] Parameter: package, Value: fr.ejn.tutorial [INFO] Parameter: packageInPathFormat, Value: fr/ejn/tutorial [INFO] Parameter: version, Value: 1.0 [INFO] Parameter: package, Value: fr.ejn.tutorial [INFO] Parameter: module, Value: gwtArtefact [INFO] Parameter: groupId, Value: fr.ejn.tutorial [INFO] Parameter: artifactId, Value: gwtArtefact [INFO] project created from Archetype in dir: E:\workspaces\gwt\gwtArtefact [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24 seconds [INFO] Finished at: Tue Jan 24 23:16:16 CET 2012 [INFO] Final Memory: 15M/998M [INFO] ------------------------------------------------------------------------
Le pom parent sera modifié pour prendre en compte le nouveau module.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Project Information -->
<artifactId>myParentPom</artifactId>
<description></description>
<groupId>myGroupId</groupId>
<name>My Application</name>
<packaging>pom</packaging>
<version>1.0</version>
<build>
<!-- Force the archetype plugin for maven, for archetype creation. -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
<properties>
<!-- Use a custom version of GXT. Do not forget to upload the artifact into a server like Nexus. -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- GWT only works with 1.6 -->
<maven.compile.source>1.6</maven.compile.source>
<maven.compile.target>1.6</maven.compile.target>
</properties>
<modules>
<module>gwtArtefact</module>
</modules>
</project>
Fichiers générés
Le résultat de l'exécution va générer un ensemble de fichiers, et même des fichiers de configuration pour Eclipse.
│ .classpath │ .project │ gwtArtefactTest-dev.launch │ gwtArtefactTest-prod.launch │ pom.xml │ ├───.settings │ .jsdtscope │ com.google.appengine.eclipse.core.prefs │ com.google.gdt.eclipse.core.prefs │ com.google.gwt.eclipse.core.prefs │ org.eclipse.jdt.core.prefs │ org.eclipse.wst.common.component │ org.eclipse.wst.common.project.facet.core.xml │ org.eclipse.wst.jsdt.ui.superType.container │ org.maven.ide.eclipse.prefs │ ├───src │ ├───main │ │ ├───java │ │ │ └───fr │ │ │ └───ejn │ │ │ └───tutorial │ │ │ ├───client │ │ │ │ GreetingService.java │ │ │ │ gwtArtefact.java │ │ │ │ │ │ │ ├───server │ │ │ │ GreetingServiceImpl.java │ │ │ │ │ │ │ └───shared │ │ │ FieldVerifier.java │ │ │ │ │ ├───resources │ │ │ └───fr │ │ │ └───ejn │ │ │ └───tutorial │ │ │ │ gwtArtefact.gwt.xml │ │ │ │ │ │ │ └───client │ │ │ Messages.properties │ │ │ Messages_fr.properties │ │ │ │ │ └───webapp │ │ │ gwtArtefact.css │ │ │ gwtArtefact.html │ │ │ │ │ └───WEB-INF │ │ web.xml │ │ │ └───test │ ├───java │ │ └───fr │ │ └───ejn │ │ └───tutorial │ │ └───client │ │ GwtTestgwtArtefact.java │ │ │ └───resources │ └───fr │ └───ejn │ └───tutorial │ gwtArtefactJUnit.gwt.xml │ └───target └───generated-sources └───gwt └───fr └───ejn └───tutorial
L'identifiant de l'artifact, et du groupe, est donc très important car repris dans les paquets Java et les noms des services. Le fichier souhaité dans le cadre de cette étude, est le pom.xml
afin d'en étudier son contenu.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>gwtStudy</artifactId>
<groupId>fr.ejn.tutorial</groupId>
<version>1.0</version>
</parent>
<groupId>fr.ejn.tutorial</groupId>
<artifactId>gwtArtefact</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>GWT Maven Archetype</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.4.0</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<runTarget>gwtArtefact.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>fr.ejn.tutorial.client.Messages</i18nMessagesBundle>
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Le fichier généré est fort pratique, mais comporte certains paramètres qui sont incompatibles avec les outils souhaités:
- Version de junit à 4.7
- Version de compilation en 1.5
Le contenu de ce fichier sera donc une bonne base de départ pour la construction d'un projet manuellement.
Un autre avantage concerne la création des tests unitaires, donnant un aperçu des possibilités, ainsi que des fichiers de localisations pour internationaliser l'application.
Voir Aussi
Documentation officielle: http://mojo.codehaus.org/gwt-maven-plugin