创建一个入门的JAVA WEB站点(REST JERSEY)

最近一直在看TOMCAT,想要自己创建一个小WEB站点,有不想要部署在其他的容器内这是一个不错的学习对象。

一、选择合适的模版

mvn archetype:generate -DarchetypeCatalog=http://download.java.net/maven/2

二、选择模版

[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)  
Choose archetype:  
1: http://download.java.net/maven/2 -> com.sun.jersey.archetypes:jersey-quickstart-grizzly (Archetype for creating a RESTful web application with Jersey and Grizzly)  
2: http://download.java.net/maven/2 -> com.sun.jersey.archetypes:jersey-quickstart-grizzly2 (Archetype for creating a RESTful web application with Jersey and Grizzly 2.x)  
3: http://download.java.net/maven/2 -> com.sun.jersey.archetypes:jersey-quickstart-webapp (Archetype for creating a Jersey based RESTful web application with WAR packaging)  
4: http://download.java.net/maven/2 -> com.sun.jersey.archetypes:jersey-quickstart-ejb (Archetype for creating a Jersey based RESTful EJB application with WAR packaging)  
5: http://download.java.net/maven/2 -> com.sun.faces:simple-jsf (Archetype for creating a simple JSF project)  
6: http://download.java.net/maven/2 -> com.sun.faces.regression:i_jsf_XXXX-archetype (Archetype for mojarra JSF regression tests)  

三、填入信息

Define value for property 'groupId': : com.esri  
Define value for property 'artifactId': : carrier  
Define value for property 'version':  1.0-SNAPSHOT: :   
Define value for property 'package':  com.esri: :   
Confirm properties configuration:  
groupId: com.esri  
artifactId: carrier  
version: 1.0-SNAPSHOT  
package: com.esri  
 Y: : y  

四、进入目录,编译

$ cd carrier
$ mvn clean package

五、执行程序: mvn exec:java

$ mvn exec:java
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.taobao:carrier:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 63, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building carrier 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.1:java (default-cli) @ carrier >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.1:java (default-cli) @ carrier <<<
[INFO]
[INFO] --- exec-maven-plugin:1.1:java (default-cli) @ carrier ---
Starting grizzly...
2013-8-14 15:30:05 com.sun.grizzly.Controller logVersion
信息: GRIZZLY0001: Starting Grizzly Framework 1.9.31 - 13-8-14 下午3:30
Jersey app started with WADL available at http://localhost:9998/application.wadl
Hit enter to stop it...

六、测试结果,访问:http://localhost:9998/myresource 和 http://localhost:9998/application.wadl

 

From: http://blog.csdn.net/csfreebird/article/details/8152437

posted @ 2013-08-14 15:32  李秋  阅读(800)  评论(0编辑  收藏  举报