Apache Maven是一个软件项目管理的综合工具(management and comprehension tool)。可以将WAR文件部署到App Engine中。为了加快部署的速度,App Engine团队提供了插件和Maven原型这两个东西(plugin and Maven Archetypes)。

注意:使用Maven时,你不需要从Google App Engine SDK下载java库。Maven会为你做这个事情。你也可以使用Maven在本地测试你的应用,以及将应用部署到生产环境的App Engine。

先决条件

1.安装Java 7。

2.设置环境变量JAVA_HOME 。

3.安装Maven

App Engine Managed VMs Maven projects 的处理不同

Maven projects 和 Eclipse

Maven项目和Eclipse项目有不同的结构(layout)。要在Eclipse中使用Maven项目,需要使用Eclipse for Java Enterprise Edition,它支持Maven。并且需要使用下面方法中的一个:

● 将Maven项目导入到Eclipse

● 将Maven项目作为一个WTP(Web Tools Platform)项目导入到Eclipse

● 设置两个Debug配置。一个为devserver中的Maven项目(mvn:appengine:devserver),一个为远程Java应用,你将使用它连接devserver jvm和Eclipse debug client。

具体怎么做,可以参考这个StackOverflow 问题的回答How do I make Eclipse and mvn appengine:devserver talk to each other?

你需要知道的Maven术语

在项目的创建过程中,Maven提示你需要提供这个项目的groudId,artifactId,version,以及package。这些在Maven中代表什么呢?

术语 含义
groupId Maven中的命名空间来跟踪你的artifacts。当别人在他们的项目中使用你的项目时,这个就是他们指定的依赖属性。
artifactId 在Maven中,你的项目的名字。当你的项目的用户在他们自己的Maven项目中依赖你时,也可以指定为你的项目的用户。
version 你希望你的项目生成时使用的原始的Maven版本。让其以-SNAPSHOT结尾是一个不错的想法。因为这样做可以对开发中的版本Maven release Plugin的支持。
package 这一代创建的Java包

Maven App Engine archetypes

Maven archetypes允许用户使用覆盖了公共场景的模板来创建Maven项目。App Engine利用了这个Maven特性,在Maven中心提供了一些有用的 App Engine archetypes 。

目前的App Engine artifacts列在下面:

应用类型 Artifact 描述
App Engine app* guestbook-archetype 生成guestbook demo例子,完成并可以运行、测试
App Engine app* appengine-skeleton-archetype 为你自己的类和资源创建一个新的包含必须的文件和目录的空App Engine项目。
Cloud Endpints API backend hello-endpoints-archetype 一个Cloud Endpoints backend API 项目例子
Cloud Endpints API backend endpoints-skeleton-arhcetype 为你自己的类和资源创建一个新的包含必须的文件和目录的空Cloud Endpoints backend API 项目。

App Engine app*表示一个标准的App Engine app,不是Cloud Endpoints backend API。

向存在的Maven项目添加App Engine Maven Plugin

在项目的pom.xml文件中增加plugins部分:

<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.22</version>
</plugin>

指定本地测试的一个端口

本地运行的默认端口是8080,。可以通过修改appengine-maven-plugin条目来改变。

 <plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.22</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
<port>8181</port>
<address>0.0.0.0</address>
</configuration>
</plugin>

此处将端口设置为8181;地址指定为0.0.0.0,这意味着development server将会侦听来自本地网络的请求。

使用App Engine Maven Plugin管理和运行一个项目

App Engine Maven Plugin支持在Maven中的App Engine。它提供了使用development server以及appcfg工具的大多数功能。

The plugin also provides Google Cloud Endpoints goals for discovery doc generation and client library generation.

一旦App Engine Maven Plugin被添加到了pom.xml中,一些Engine-specific Maven goals 就可以得到。查看所有可以获得的目标,调用命令:

mvn help:describe -Dplugin=appengine

App Engine Maven plugin 目标

App Engine Maven plugin 目标可以分类为devserver目标、应用和项目管理目标、Endpoints目标。

Development server目标

appengine:devserver

运行development server。当server运行时,它会继续检查appengine-web.xml是否发生了改变。这意味着appengine-web.xml发生改变时不需要停止再启动你的应用。

appengine:devserver_start

异步启动

appengine:devserver_stop

停止由appengine:devserver_start启动的development server

Troubleshooting upload errors

发生错误:404 Not Found This application does not exist (app_id=u'your-app-ID')

原因:有多个Google账户,使用了错误的账户

解决方法:切换到~目录,重命名.appcfg_oauth2_tokens_java之后再重试。

Using Apache Maven的更多相关文章

  1. maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang

    maven打包成war时,报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default- ...

  2. Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (dist) on project hadoop-kms: An Ant BuildException has occured

    编译cdh版hadoop2.5.0出现的问题 系统: CentOs66 64位 JDK:1.7 Maven: 3.0.5 Protobuf: libprotoc 2.5.0 编译命令: mvn pac ...

  3. eclipse加载maven工程提示pom.xml无法解析org.apache.maven.plugins:maven-resources-plugin:2.4.3解决方案

    pom文件提示信息: Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 from http:/ ...

  4. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project LogTest: Compilation failure -> [Help 1]

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default ...

  5. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:

    security-sdk-1.0.jar已经存在于D:/secServerSDK-test/src/main/resources/lib下 报错如下: xxxxxx@xxxxxxxx /d/secSe ...

  6. maven Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repositories 解决

    报错:Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repos ...

  7. [Maven]Apache Maven 入门篇

    作者:George Ma 上 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这个想法.这个入门篇分上下两篇.本文着重动手,用 ma ...

  8. apache maven pom setting

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  9. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of 3: mojo org.apache.maven.plugins:

    问题: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (defau ...

  10. Apache Maven 入门篇 ( 上 )

    作者:George Ma 写这个 maven 的入门篇是因为之前在一个开发者会的动手实验中发现挺多人对于 maven 不是那么了解,所以就有了这个想法. 这个入门篇分上下两篇.本文着重动手,用 mav ...

随机推荐

  1. iOS KVO的原理

    KVO(Key Value Observing),是观察者模式在Foundation中的实现.   KVO的原理   简而言之就是:   1.当一个object有观察者时,动态创建这个object的类 ...

  2. Servlet的response输出到页面时乱码的解决方法

    package com.mhb; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servle ...

  3. Java API —— ArrayList类 & Vector类 & LinkList类

    1.ArrayList类     1)ArrayList类概述         · 底层数据结构是数组,查询快,增删慢         · 线程不安全,效率高     2)ArrayList案例   ...

  4. centos 安装openssl 以及库文件

    yum install openssl yum install openssl-devel

  5. Android Studio设置,鼠标放上去有提示

    设置如下: 1. 2. 勾选就可以了

  6. Android adb 常用技巧

    1.在命令行管理模拟器设备(AVD) list:列出机器上所有已经安装的Android版本和AVD设备 list avd:列出机器上所有已经安装的AVD设备: list target:列出机器上所有已 ...

  7. 字符串模式匹配sunday算法

    文字部分转自:http://www.cnblogs.com/mr-ghostaqi/p/4285868.html 代码是我自己写的 今天在做LeetCode的时候,碰到一个写字符串匹配的题目: htt ...

  8. std::ofstream由二进制流写文件的问题

    从MPQ包中读取二进制流出来然后文件写到硬盘. DWORD size = SFileGetSize(hFile); char* buffer = new char[size]; std::ofstre ...

  9. int和integer;Math.round(11.5)和Math.round(-11.5)

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

  10. uva1262Password

    解码,暴力. 恬不知耻地把暴力题解放了上来,因为k比较小,直接暴力找到字符串第k大就可以了. 编码解码就是根据组合数学公式算出来它到底在哪. dfs返回bool就能使得找到字典序第k大字符串以后退出d ...