2014-04-23 67 views
0

我根據this文檔創建了Google App Engine maven項目,並且它可以成功運行。然後,我通過使用選項現有的Maven項目將相同的項目導入到eclipse中。但是在eclipse中,它只有一個沒有java facet的maven項目。然後右鍵點擊Project - > Properties - > Project Facet - >在java選項上勾選Tick。現在eclipse在我創建的應用程序上顯示java錯誤(對於某些與應用程序引擎相關的類)。但是這個項目使用maven命令很好,例如mvn clean installmvn appengine:devserver。下面是我的maven項目的pom爲GAE maven項目添加java facet

<?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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.google.appengine.demos</groupId> 
    <artifactId>guestbook</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <appengine.target.version>1.9.0</appengine.target.version> 
    </properties> 

    <build> 
     <pluginManagement> 
      <plugins> 
       <plugin> 
        <groupId>com.google.appengine</groupId> 
        <artifactId>appengine-maven-plugin</artifactId> 
        <version>${appengine.target.version}</version> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 
    <modules> 
    <module>guestbook-war</module> 
    <module>guestbook-ear</module> 
    </modules> 
</project> 

回答

1

您似乎沒有任何依賴關係在您的pom中。這些定義您的應用程序依賴的庫。最低限度,對於應用服務引擎的戰爭,你需要這樣的事:

<dependencies> 
    <!-- Servlet dependencies --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.el</groupId> 
     <artifactId>javax.el-api</artifactId> 
     <version>2.2.4</version> 
     <scope>provided</scope> 
    </dependency> 

    <!-- GAE Dependencies --> 
    <dependency> 
     <groupId>com.google.appengine</groupId> 
     <artifactId>appengine-api-1.0-sdk</artifactId> 
     <version>${gae.version}</version> 
     <scope>compile</scope> 
    </dependency> 
</dependencies> 

如果你也想做一些單元測試,你需要添加下面的上述塊:

  <!-- Test Dependencies --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.11</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hamcrest</groupId> 
     <artifactId>hamcrest-all</artifactId> 
     <version>1.3</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-all</artifactId> 
     <version>1.9.5</version> 
     <scope>test</scope> 
    </dependency>  
    <dependency> 
     <groupId>com.google.appengine</groupId> 
     <artifactId>appengine-testing</artifactId> 
     <version>${gae.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.appengine</groupId> 
     <artifactId>appengine-api-stubs</artifactId> 
     <version>${gae.version}</version> 
     <scope>test</scope> 
    </dependency> 

如果您想在eclipse中工作,請確保安裝了wtp-m2e eclipse插件,並安裝了Google Plugin for Eclipse插件。他們會讓你的生活變得更輕鬆。

+0

請注意,Google插件for Eclipse工具現在已被棄用,因此您應該使用[Google雲端工具for Eclipse](https://cloud.google.com/eclipse/docs/)插件。 –

相關問題