BAE Maven开发笔记

使用bae 做自己的server端,现在将学习的过程记录下来。

1.部署环境

2.helloworld

3.开发

----------------

1.部署环境

在看到bae支持使用maven后,感觉世界一下子变的好整洁。BAE使用的maven目录结构很标准的maven目录:


BAE Maven开发笔记_第1张图片

根据官方教程,给mave环境配置好。


2. HelloWorld

根据http://godbae.duapp.com/?p=163 教程,给bae maven的HelloWorld给搞定,需要的maven 配置文件 pom.xml 内容如下:

<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>______your_group_id__________</groupId>
    <artifactId>_____your_artifactid______</artifactId>
    <version>1.0</version>
    <name>___your_app_name</name>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.baidu.bce.javaruntime</groupId>
            <artifactId>bae-sdk</artifactId>
            <version>1.0.23.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.baidu.bce.javaruntime</groupId>
            <artifactId>bce-api-util</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.baidu.bce.javaruntime</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
            <classifier>bin</classifier>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.baidu.bce.javaruntime</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.1.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.baidu.bce.javaruntime</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j-adapter</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>


    <repositories>
        <repository>
            <id>baemaven</id>
            <name>BAE Maven</name>
            <url>http://maven.duapp.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>baemaven</id>
            <name>BAE Maven</name>
            <url>http://maven.duapp.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.baidu.bae.maven</groupId>
                <artifactId>bae-maven-plugin</artifactId>
                <version>1.0.0.0</version>
                <executions>
                    <execution>
                        <id>baedeploy</id>
                        <phase>install</phase>
                        <goals>
                            <goal>baedeploy</goal>
                        </goals>
                        <configuration>
                            <changepass>false</changepass>
                            <appid>_____your_appid___</appid>
                            <version>1</version>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.baidu.bae.maven.jetty</groupId>
                <artifactId>bae-maven-jetty-plugin</artifactId>
                <version>8.0.0.M3</version>
                <configuration>
                    <jettyport>8080</jettyport>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

第一次可以先使用mvn dependency:resolve 来下载所有的依赖,第一次可能要看网络的情况(看人品)

maven的版本尽量不要用3.1.× 这个版本的好像有很多问题(在本文发布时,一些问题依然没有解决),建议用3.0.5

3.开发

开发注意的一点就是自己的servlet 在继承 javax.servlet.http.HttpServlet; 实现 doXXX(GET,POST,DELETE,PUT)的时候不调用super。



你可能感兴趣的:(maven,servlet,BAE)