简体   繁体   English

无法通过导入现有的maven项目将gwt-maven-plugin生成的maven项目导入eclipse

[英]The maven project generated by gwt-maven-plugin can't be imported into eclipse via import existing maven project

I firstly generated a gwt maven project by executing -- 我首先通过执行-生成了gwt maven项目

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

After that, the pom.xml is as follows: 之后,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>

Then I imported this project into eclipse via built-in eclipse function -- import existing Maven project. 然后我通过内置的eclipse函数将该项目导入eclipse -导入现有的Maven项目。

However, the process failed due to several reasons: 但是,由于以下几个原因,该过程失败了:

  1. GreetingServiceAsync cannot be resolved to a type GreetingServiceAsync无法解析为一种类型
  2. Execution default of goal org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync failed: 目标org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync执行默认设置失败:

Plugin org.codehaus.mojo:gwt-maven-plugin:2.7.0 or one of its dependencies could not be resolved: Failed to collect dependencies for org.codehaus.mojo:gwt-maven-plugin:jar:2.7.0 () (org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync:default:generate-sources) 插件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 plugin can't identify this project as gwt web application automatically. google插件无法自动将该项目标识为gwt网络应用程序。

My environment as follows: 我的环境如下:

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

Please advice, thanks a lot! 请指教,非常感谢!

The problem was with generateAsync, which in your case generates GreetingServiceAsync on execution. 问题出在generateAsync上,在您的情况下,它会在执行时生成GreetingServiceAsync。 Eclipse probably wasn't configured to handle it properly and this class was not generated and eclipse reported the missing class warning. Eclipse可能未配置为正确处理它,并且未生成此类并且eclipse报告缺少的类警告。

Another thing that could be done to get the project to work was to run mvn package from command line and add the generated dir in target dir as source dir in eclipse (vie right clicking the project and selecting New -> source folder > browsing folder name > target > generated-sources > the right folder) 要使项目正常工作,可以做的另一件事是从命令行运行mvn软件包,并在目标目录中将生成的目录添加为eclipse中的源目录(右键单击该项目,然后选择“新建”->“源文件夹”>“浏览文件夹名称” >目标>生成源>正确的文件夹)

Also you may run into same issue after you do mvn clean - the generated GreetingServiceAsync will be deleted and the problem may come back. 另外,在执行mvn clean之后,您可能会遇到相同的问题-生成的GreetingServiceAsync将被删除,问题可能会再次出现。

The problem exists because eclipse isn't tightly integrated with maven and uses its own build system ignoring maven targets that you don't have plugins for. 之所以存在这个问题,是因为eclipse没有与maven紧密集成,并且使用它自己的构建系统忽略了您没有插件的maven目标。 What you could do is to open eclipse preferences > maven > lifecycle mappings and there you can enable generateAsync to execute. 您可以做的是打开eclipse首选项> maven>生命周期映射,然后可以在其中启用generateAsync来执行。

If you copy the generated class manually you have to keep in mind that you need to update it when needed, where as it is intended to generate automatically. 如果手动复制生成的类,则必须记住,需要在需要时对其进行更新,因为该类将自动生成。 So you loose this convenience. 因此,您失去了这种便利。

I did another attempt to try in a win32 computer, the problem re-appeared even if I set up the environment as aforementioned working in my win64 computer. 我再次尝试在Win32计算机上进行尝试,即使我按照上述在Win64计算机上工作的方式设置了环境,问题仍然出现。

So I really got confused, like Klarki said, I have to do some tweaks to get it work. 所以我真的很困惑,就像克拉尔基所说的那样,我必须做一些调整才能使其正常工作。 I generated GreetingServiceAsync via mvn gwt:generateAsync then manually copy GreetingServiceAsync to source folder, then I remove <goal>generateAsync</goal> in pom.xml, then import project via eclipse's existing maven project. 我通过mvn gwt:generateAsync生成了GreetingServiceAsync,然后手动将GreetingServiceAsync复制到源文件夹,然后删除pom.xml中的<goal>generateAsync</goal> ,然后通过eclipse的现有maven项目导入项目。 It works again! 它再次起作用!

Sadly see it not working intelligently. 可悲的是,它无法正常工作。

This work for me: 这项工作对我来说:

I deleted the local maven gwt repository, in windows 7 it's in C:\\Users\\.m2\\repository\\com\\google\\gwt, and then make a 我删除了本地Maven gwt存储库,在Windows 7中,它位于C:\\ Users \\ .m2 \\ repository \\ com \\ google \\ gwt中,然后创建一个

mvn clean complile

so maven re-import al dependencys. 所以行家重新导入所有依赖。

After I changed my environment as follows: 在按如下所示更改环境后:

  1. java version "1.8.0_05" Java版本“ 1.8.0_05”
  2. eclipse Version: Luna Release (4.4.0) eclipse版本:Luna版本(4.4.0)
  3. Google plugin for Eclipse 4.4 Eclipse 4.4的Google插件

I works like a charm. 我像一个魅力。

Probably, it's a version incompatibility issue. 可能是版本不兼容的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM