昨天折腾了好久才弄好GWT+Maven+NetBeans的整合配置,今天就看到有人写了篇Maven+GWT的POM配置指南,当真是很不爽,于是偷过来贴在这泄愤了!
原文:Maven2 + GWT 1.5.3 + all platforms + tests
软件版本:
- GWT 1.5.3
- Maven 2.0.9
POM.XML文件内容如下:
- <!-- http://docs.codehaus.org/display/MAVENUSER/Profiles -->
- <profiles>
-
- <profile>
- <id>mac</id>
- <activation>
- <os>
- <family>mac</family>
- </os>
- </activation>
- <properties>
- <os>mac</os>
- </properties>
- </profile>
- <profile>
- <id>linux</id>
- <activation>
- <os>
- <name>linux</name>
- </os>
- </activation>
- <properties>
- <os>linux</os>
- </properties>
- </profile>
- <profile>
- <id>windows</id>
- <activation>
- <os>
- <family>windows</family>
- </os>
- </activation>
- <properties>
- <os>windows</os>
- </properties>
- <dependencies>
- <dependency>
- <groupId>com.google.gwt</groupId>
- <artifactId>dev-${os}</artifactId>
- <version>${gwtVersion}</version>
- <scope>system</scope>
- <systemPath>
- ${basedir}/gwt/gwt-${os}-${gwtVersion}/gwt-dev-${os}.jar
- </systemPath>
- </dependency>
- </dependencies>
- </profile>
- </profiles>
----------------------懒得翻译,下面直接贴原文内容----------------------
Note the profiles achieves two things:
Set the ${os} property (this cannot be achieved otherwise)
Add a dependency to the gwt-dev jar - which must reside in the same directoy as some other OS-specific files.
We still need to make sure that the OS-specific part is at the right place (here: ${basedir}/gwt ) at the right time (here: before using the dependencies for compile or test).
Next we need to declare the GWT specific dependencies in the pom. We simply uploaded those to our public maven repository as well (http://semweb4j.org/repo)
- <!-- gwt dependencies -->
- <dependency>
- <groupId>com.google.gwt</groupId>
- <artifactId>gwt-user</artifactId>
- <version>${gwtVersion}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>com.google.gwt</groupId>
- <artifactId>gwt-servlet</artifactId>
- <version>${gwtVersion}</version>
- </dependency>
Now comes the clever part:
- <dependency>
- <groupId>com.google.gwt</groupId>
- <artifactId>dist-${os}</artifactId>
- <version>${gwtVersion}</version>
- </dependency>
This instructs maven to fetch our special GWT-dist jar. We also need to unpack it at the right time, which is done here, in :
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>unpack-gwt</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>com.google.gwt</groupId>
- <artifactId>dist-${os}</artifactId>
- <version>1.5.3</version>
- <type>jar</type>
- <overWrite>true</overWrite>
- <outputDirectory>
- ${basedir}/gwt
- </outputDirectory>
- </artifactItem>
- </artifactItems>
- <!-- other configurations here -->
- </configuration>
- </execution>
- </executions>
- </plugin>