【问题标题】:The maven project generated by gwt-maven-plugin can't be imported into eclipse via import existing maven projectgwt-maven-plugin生成的maven项目无法通过import existing maven project导入eclipse
【发布时间】:2015-01-23 22:09:50
【问题描述】:

我首先通过执行——生成了一个gwt maven项目——

mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.7.0

之后的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">

      <modelVersion>4.0.0</modelVersion>
      <groupId>com.boye.games</groupId>
      <artifactId>games-gwt</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>GWT Maven Archetype</name>

      <properties>
        <!-- Convenience property to set the GWT version -->
        <gwtVersion>2.7.0</gwtVersion>

        <!-- GWT needs at least java 1.6 -->
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt</artifactId>
            <version>${gwtVersion}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>
      </dependencyManagement>

      <dependencies>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-servlet</artifactId>
          <scope>runtime</scope>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-user</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-dev</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

      <build>
        <!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

        <plugins>

          <!-- GWT Maven Plugin -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.7.0</version>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>test</goal>
                  <goal>generateAsync</goal>
                </goals>
              </execution>
            </executions>
            <!-- Plugin configuration. There are many available options, see 
              gwt-maven-plugin documentation at codehaus.org -->
            <configuration>
              <runTarget>LineThree.html</runTarget>
              <modules>
                <module>com.boye.games.linethree.LineThree</module>
              </modules>
            </configuration>
          </plugin>
        </plugins>
      </build>

    </project>

然后我通过内置的 eclipse 功能将这个项目导入到 eclipse 中——导入现有的 Maven 项目。

但是,由于以下几个原因,该过程失败了:

  1. GreetingServiceAsync 无法解析为类型
  2. 目标org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync的执行默认失败:

插件 org.codehaus.mojo:gwt-maven-plugin:2.7.0 或其之一 无法解析依赖项:无法收集依赖项 org.codehaus.mojo:gwt-maven-plugin:jar:2.7.0 () (org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync:default:generate-sources)

  1. google 插件无法自动将此项目识别为 gwt web 应用程序。

我的环境如下:

  1. java 版本 1.7.0_03
  2. eclipse 版本 Kepler Service Release 2
  3. gwt 版本 2.7.0

请指教,万分感谢!

【问题讨论】:

    标签: eclipse maven gwt google-eclipse-plugin


    【解决方案1】:

    在我改变了我的环境之后:

    1. java版本“1.8.0_05”
    2. eclipse 版本:Luna Release (4.4.0)
    3. Eclipse 4.4 的谷歌插件

    我的工作就像一个魅力。

    可能是版本不兼容的问题。

    【讨论】:

    • 这在我的另一台电脑win32上不起作用,它只在我的win64电脑上成功。很奇怪!
    • 这不是 gwt-maven-plugin 解决方案。
    【解决方案2】:

    问题出在 generateAsync 上,在您的情况下,它会在执行时生成 GreetingServiceAsync。 Eclipse 可能未配置为正确处理它,并且未生成此类,并且 Eclipse 报告了缺少类警告。

    为了使项目工作可以做的另一件事是从命令行运行 mvn package 并将生成的目录添加到目标目录中作为 eclipse 中的源目录(查看右键单击项目并选择新建 -> 源文件夹>浏览文件夹名称>目标>生成源>正确的文件夹)

    在你执行 mvn clean 之后你可能会遇到同样的问题 - 生成的 GreetingServiceAsync 将被删除并且问题可能会再次出现。

    问题的存在是因为 eclipse 没有与 maven 紧密集成,并且使用自己的构建系统忽略了您没有插件的 maven 目标。您可以做的是打开 eclipse 首选项 > maven > 生命周期映射,然后您可以启用 generateAsync 来执行。

    如果您手动复制生成的类,您必须记住,您需要在需要时更新它,因为它打算自动生成。所以你失去了这种便利。

    【讨论】:

    • 谢谢你,Klarki,我做了类似的事情来让它工作。请在下面查看我的答案。
    【解决方案3】:

    我再次尝试在win32计算机上尝试,即使我在我的win64计算机上设置了上述环境,问题仍然出现。

    所以我真的很困惑,就像 Klarki 说的,我必须做一些调整才能让它发挥作用。我通过 mvn gwt:generateAsync 生成 GreetingServiceAsync 然后手动将 GreetingServiceAsync 复制到源文件夹,然后我在 pom.xml 中删除&lt;goal&gt;generateAsync&lt;/goal&gt;,然后通过 eclipse 现有的 maven 项目导入项目。它再次起作用了!

    遗憾地看到它不能智能地工作。

    【讨论】:

    • 我认为更好的选择是首先在项目上运行目标 gwt:generateAsync ,它将在 target/generated-sources 文件夹中创建所需的源,该文件夹会自动添加到您的构建路径中源文件夹。这应该可以解决问题。在最坏的情况下,您可能需要手动刷新您的项目
    【解决方案4】:

    这对我有用:

    我删除了本地的maven gwt仓库,在windows 7里面是C:\Users\.m2\repository\com\google\gwt,然后make a

    mvn clean complile
    

    so maven 重新导入所有依赖项。

    【讨论】:

      猜你喜欢
      • 2012-11-18
      • 1970-01-01
      • 2012-08-31
      • 2017-05-24
      • 2011-11-23
      • 2012-02-02
      • 2011-11-16
      • 2011-12-16
      • 2012-06-03
      相关资源
      最近更新 更多