微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Maven GWT项目找不到类

如何解决Maven GWT项目找不到类

我们不得不迁移一个gwt项目,然后我们开始使用maven。我们现在很难重新启动它。这是第一次与Maven合作,所以请忍受我

我执行以下命令时没有错误

mvn gwt:compile

mvn软件包

mvn gwt:run

现在码头给了我以下网址:http://127.0.0.1:8888/Aprov.html?gwt.codesvr=127.0.0.1:9997 

enter image description here

当我尝试在firefox中访问该URL时,它会正确加载Web元素,但是似乎无法访问这些类:

enter image description here

在码头我得到了错误

enter image description here

在日食中我得到了错误

enter image description here

在我的pom.xml中,我指定此位置:

enter image description here

如果我检查了mvn包是否正确执行了,这是它找不到的类:

enter image description here

尽管文件位于正确的位置,但它们不会出现在eclipse中,但我会说没关系:

enter image description here

class文件夹没有在eclipse中显示,但是它在Windows资源管理器中,由mvn软件包生成

这是pom.xml文件

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>
  <version>0.1.0-SNAPSHOT</version>

  <groupId>bbva.cib</groupId>
  <artifactId>Aprov</artifactId>

  <properties>
    <appengine.maven.plugin.version>2.4.0</appengine.maven.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
    
    <!-- WebApp/War Output Directory -->
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <!-- for hot reload of the web application-->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <sourceDirectory>src</sourceDirectory>    
    
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>libraries-bom</artifactId>
        <version>14.4.1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
           <groupId>com.google.gwt</groupId>
           <artifactId>gwt</artifactId>
           <version>2.7.0</version>
           <type>pom</type>
           <scope>import</scope>
       </dependency>
    </dependencies>
   </dependencyManagement>

  <dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>2.3.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.83</version>
    </dependency>
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-framework</artifactId>
        <version>2.2.1</version>
    </dependency>
    
    <!-- Test Dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.4.5</version>
        <scope>provided</scope>         
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.5</version>
        <scope>provided</scope>         
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-excelant</artifactId>
        <version>3.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-examples</artifactId>
        <version>3.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-scratchpad</artifactId>
        <version>3.12</version>
    </dependency>   
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.1</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/com.google.gwt/gwt-servlet -->
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>2.7.0</version>
        <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>
     
    
  </dependencies>


  <build>
    <!-- for hot reload of the web application-->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <plugins>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.maven.plugin.version}</version>
      </plugin>
      <plugin>
         <groupId>org.eclipse.jetty</groupId>
         <artifactId>jetty-maven-plugin</artifactId>
      </plugin>
      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.0.0-M3</version>
        <executions>
          <execution>
            <id>enforce-maven</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <!-- appengine-maven-plugin requires Maven 3.5.0 or later -->
                <requireMavenVersion>
                  <version>3.5.0</version>
                </requireMavenVersion>
              </rules>
            </configuration>
          </execution>
        </executions>
      </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>
                        </goals>
                    </execution>
                </executions>
                <!-- Plugin configuration. There are many available options,see gwt-maven-plugin 
                    documentation at codehaus.org -->
                <configuration>
                    <runTarget>Aprov.html</runTarget>
                    <hostedWebapp>${webappDirectory}</hostedWebapp>
                    <superDevMode>false</superDevMode> 
                    <sourceLevel>1.7</sourceLevel>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    
                </configuration>
            </plugin>
    </plugins>
  </build>
</project>

这是greet类的web.xml部分:

 <servlet>
   <servlet-name>greetServlet</servlet-name>
   <servlet-class>bbva.cib.server.GreetingServiceImpl</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
   <servlet-name>greetServlet</servlet-name>
   <url-pattern>/aprov/greet</url-pattern>
 </servlet-mapping>

有人知道为什么它不设法加载类,仅加载Web文件吗?预先感谢

解决方法

Eclipse和Maven并不是最好的朋友。根据您创建Maven项目的方式,这可能是一个设置问题。我将使用工件创建器,在命令行上构建Maven GWT工件,从命令行运行它并检查它是否正常工作。一旦工作,我将其导入Eclipse。

您应该做的一些事情:

  • 使用Thomas Broyers GWT插件
  • 创建一个多模块Maven项目(使用上述工件创建者之一)

要运行多模块项目,请使用: mvn gwt:codeserver -pl * -client -am 启动代码服务器,并 mvn jetty:run -pl * -server -am- Denv = dev

然后调用 http:// localhost:8080 / index.html

如果您运行的GWT Maven项目没有用于客户端,共享和服务器的单独模块(请不要这样做),请使用 gwt:devmode

您发布的网址显示,您尝试运行旧的开发模式而不是SDM。

有几种创建基于Maven的GWT项目的方法。

您可以使用:

所有这些工件生成器将创建一个随时可用的工件。只需按照文档操作即可。一旦运行,添加代码。

如果您有任何疑问,请使用GWT Gitter室:https://gitter.im/gwtproject/gwt

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。