使用glassfish测试servlet3.1

glassfish4是首个支持JavaEE 7的容器,即支持servlet3.1,于是使用glassfish4 maven插件测试,但是测试时一直不成功,接着参考oracle官网的一篇《GlassFish 4 beta and Maven Embedded Plugin》终于搞定。

没办法,切换到3.1.2.2插件,但是使用4.0-b86的内嵌容器,jar包巨大无比(差不多80多M),请耐心等待。。

具体配置如下:

            <plugin>
                <groupId>org.glassfish.embedded</groupId>
                <artifactId>maven-embedded-glassfish-plugin</artifactId>
                <version>3.1.2.2</version>
                <configuration>
                    <port>9080</port>
                    <autoDelete>true</autoDelete>
                    <app>${project.build.directory}/${project.build.finalName}</app>
                    <contextRoot>${project.build.finalName}</contextRoot>
                    <name>${project.build.finalName}</name>
                    <serverID>embedded</serverID>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.glassfish.main</groupId>
                        <artifactId>simple-glassfish-api</artifactId>
                        <version>4.0-b79</version>
                    </dependency>
                    <dependency>
                        <groupId>org.glassfish.main.extras</groupId>
                        <artifactId>glassfish-embedded-all</artifactId>
                        <version>4.0-b86</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

这样可以在maven clean package时运行glassfish。 

另外,需要制定下载依赖的仓库

    <pluginRepositories>
        <pluginRepository>
            <id>maven.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>https://maven.java.net/content/groups/promoted/</url>
        </pluginRepository>
        <pluginRepository>
            <id>maven2-repository.dev.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/glassfish/</url>
        </pluginRepository>
    </pluginRepositories>

单独使用glasshfish4容器测试时没有问题的。

最近在整理servlet3.x的一份学习示例,具体可参考我的github

https://github.com/zhangkaitao/servlet3-showcase

servlet3.1的新特性可以参考

https://github.com/zhangkaitao/servlet3-showcase/tree/master/chapter4-3_1

猜你喜欢

转载自jinnianshilongnian.iteye.com/blog/1911249