使用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值