Java Maven GWT 2.0 和 Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1894003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven GWT 2.0 and Eclipse
提问by Lehane
Does anyone know of a good guide for creating a project with the new 2.0 release of GWT using maven and eclipse? I am running into a lot of problems getting them to play nicely together.
有没有人知道使用 maven 和 eclipse 使用新的 2.0 版 GWT 创建项目的好指南?我遇到了很多问题,让他们一起玩得很好。
For what it's worth, I can create a gwt project using the maven eclipse plugin which works fine, but porting it to maven doesn't work (so a guide for this would be great).
对于它的价值,我可以使用 maven eclipse 插件创建一个 gwt 项目,该插件工作正常,但将其移植到 maven 不起作用(因此这方面的指南会很棒)。
Likewise, I can use the maven plugin (gwt-maven-plugin), but when I import it to eclipse (import -> materialize maven projects), it does not get recognised as a GWT project...
同样,我可以使用 maven 插件 (gwt-maven-plugin),但是当我将它导入到 eclipse(导入 -> 实现 maven 项目)时,它不会被识别为 GWT 项目......
Thanks
谢谢
采纳答案by Pascal Thivent
EDIT:I've updated my answer with additional steps provided by the OP. Credits to the OP for the details.
编辑:我已经使用 OP 提供的其他步骤更新了我的答案。详情请归功于 OP。
I just broke my Eclipse setup trying to install the latest version of the Google Plugin for Eclipse (for GWT 2.0) so I can't confirm everything but, let's assume the following prerequisites are fulfilled:
我刚刚在尝试安装最新版本的 Eclipse 谷歌插件(用于 GWT 2.0)时破坏了我的 Eclipse 设置,所以我无法确认所有内容,但让我们假设满足以下先决条件:
- Eclipse 3.5
- Google Plugin for Eclipse (installed from http://dl.google.com/eclipse/plugin/3.5, see instructions)
- m2eclipse Plugin for Eclipse (installed from http://m2eclipse.sonatype.org/update)
- 日食 3.5
- 适用于 Eclipse 的 Google 插件(从http://dl.google.com/eclipse/plugin/3.5安装,请参阅说明)
- Eclipse 的 m2eclipse 插件(从http://m2eclipse.sonatype.org/update安装)
Did you try to:
您是否尝试过:
Create a new project from Eclipse (New > Other...then select Maven Projectand choose the gwt-maven-pluginarchetype).
Edit the generated
pom.xml
, update thegwt.version
property to2.0.0
(which has been released in the central repo),add the Codehaus Snapshotrepositoryand set thegwt-maven-plugin
version to1.2-SNAPSHOT
(the version 1.2 isn't released in central, this should happen soon)1.2
(which has been released in central too).Add a
<runTarget>
to the gwt-maven-plugin configuration as documented in Using the Google Eclipse Plugin.Configure the maven-war-plugin as documented in the page mentioned in the previous step.
Manually enable GWT on the project from project preference by setting the Use Google Web ToolkitcheckboxThis step is unnecessary since you'll be building/running with a Maven run configuration, not the GWT Plugin for Eclipse.
从 Eclipse 创建一个新项目(New > Other...,然后选择Maven Project并选择gwt-maven-plugin原型)。
编辑生成的
pom.xml
,将gwt.version
属性更新为2.0.0
(已在中央存储库中发布),添加Codehaus Snapshot存储库并将gwt-maven-plugin
版本设置为1.2-SNAPSHOT
(版本 1.2 未在中央发布,这应该很快就会发生)1.2
(已发布)也在中央)。<runTarget>
如使用 Google Eclipse 插件中所述,将a 添加到 gwt-maven-plugin 配置中。按照上一步中提到的页面中的说明配置 maven-war-plugin。
通过设置Use Google Web Toolkit复选框从项目首选项手动启用项目上的 GWT这一步是不必要的,因为您将使用 Maven 运行配置而不是 GWT 插件来构建/运行 Eclipse。
This is how my pom.xml
actually looks like:
这就是我的pom.xml
实际样子:
<?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">
<!--
GWT-Maven archetype generated POM
-->
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.demo</groupId>
<artifactId>my-gwtapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>gwt-maven-archetype-project</name>
<properties>
<!-- convenience to define GWT version in one place -->
<gwt.version>2.0.0</gwt.version>
<!-- tell the compiler we can use 1.5 -->
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
<dependencies>
<!-- GWT dependencies (from central repo) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.mycompany.demo.gwt.Application/Application.html</runTarget>
</configuration>
</plugin>
<!--
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it.
Also, exclude what you want from the final artifact here.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<warSourceDirectory>war</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run the gwt:eclipse
goal (using m2eclipse Maven2 > build...) to setup your environment and create the launch configuration for your GWT modules.
运行gwt:eclipse
目标(使用 m2eclipse Maven2 > build...)来设置您的环境并为您的 GWT 模块创建启动配置。
Run gwt:compile gwt:run
to compile and run a GWT module in the GWT Hosted mode.
运行gwt:compile gwt:run
以在 GWT 托管模式下编译和运行 GWT 模块。
回答by Pascal Thivent
Just in case. If you use Google GIN in your project you should add compilegoal before gwt:compile. So the whole sequence would be:
以防万一。如果您在项目中使用 Google GIN,则应在gwt:compile之前添加compile目标。所以整个序列将是:
compile gwt:compile gwt:run
You can read explanation here: http://code.google.com/p/google-gin/wiki/GinTutorial#Compilation
您可以在此处阅读说明:http: //code.google.com/p/google-gin/wiki/GinTutorial#Compilation
回答by chenglee
You can run the following command to generate a Maven GWT project:
您可以运行以下命令来生成 Maven GWT 项目:
webAppCreator -maven -noant -out
webAppCreator -maven -noant -out
For more information:
想要查询更多的信息:
GWT webappcreator 创建 Maven 项目:源附件不包含文件 URLClassPath.class 的源
回答by Fred Close
An annoying problem with GWT and m2eclipse:
GWT 和 m2eclipse 的一个恼人的问题:
GWT Development Mode requires all JARs to be placed in WEB-INF/lib. It's especially painful when programmers use m2eclipse, which provides its own Eclipse classpath container.
GWT 开发模式要求所有 JAR 都放在 WEB-INF/lib 中。当程序员使用 m2eclipse 时尤其痛苦,它提供了自己的 Eclipse 类路径容器。
http://code.google.com/p/google-web-toolkit/issues/detail?id=5693
http://code.google.com/p/google-web-toolkit/issues/detail?id=5693
good news, the workaround is working for me
好消息,解决方法对我有用
回答by kashili kashili
very useful thread
非常有用的线程
@Pascal: thank you (I donot have enough reputations to comment on others posts; so here I am posting on what is working for me).
@Pascal:谢谢(我没有足够的声誉来评论其他帖子;所以我在这里发布对我有用的东西)。
I needed 2.5.1 GWT (not 2.6, the latest) working with maven and eclipse (because sencha GXT is not supported for 2.6 yet). Tried following without luck
我需要 2.5.1 GWT(不是 2.6,最新的)与 maven 和 eclipse 一起工作(因为 sencha GXT 尚不支持 2.6)。尝试跟随没有运气
1)tried few archetypes with in eclipse to generate the project
1)在eclipse中尝试了几个原型来生成项目
2)modify pom file (based on above discussion) to change versions to 2.5.1
2)修改pom文件(基于以上讨论)将版本更改为2.5.1
Following worked for me http://mojo.codehaus.org/gwt-maven-plugin/user-guide/archetype.html
以下为我工作http://mojo.codehaus.org/gwt-maven-plugin/user-guide/archetype.html
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.5.1
mvn gwt:eclipse
mvn gwt:run