Servlet 3.0 ã®è¶ ã·ã³ãã«ãªãµã³ãã« ï¼pom ãï¼
ã¡ãã£ã¨ãã Java ã®ã©ã¤ãã©ãªä½¿ããµã¼ãæ¸ããªãããããªãã£ãã®ã§ããã
æè§ãªã®ã§ãServlet 3.0 ã§æ¸ãã¦ã¿ããé¼»è¡ãåºãã»ã©ç°¡åã§ãä»ã¾ã§ web.xml ã¨ãæ¸ãã¦ãã®ã¯ãªãã ã£ããã ç¶æ
ã«ãªã£ãã®ã§ã
è¶
ã·ã³ãã«ãªãµã³ãã«æ¸ãã¦ã¿ã¾ããã
package org.yoshiori; import java.io.IOException; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/test") public class ServletTest extends HttpServlet{ private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print(new Date() + ": hoge"); } }
ã»ãã¨ãããã ãã
web.xml ã¨ããã®å¤ã®è¨å®ãã£ãããããªãã
ã¤ãã§ã« pom ãæ¸ãã¦ããã¨
<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>org.yoshiori</groupId> <artifactId>servlet_test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>servlet_test</name> <url>http://maven.apache.org</url> <dependencies> <!-- SERVLET 3.0 --> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>servlet-test</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <!-- web.xml ãç¡ãã¦ã mvn package åºæ¥ãããã« --> </configuration> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> </configuration> </plugin> </plugins> </build> </project>
ãããªæã
pom ã«ã¯ jetty ã®è¨å®ãå
¥ãã¦ãããã®ã§ã
$ mvn jetty:run
ã㦠http://localhost:8080/test ã«ã¢ã¯ã»ã¹ããã°ä¸è¨ã®ãã¼ã¸ãè¦ãã¾ããã
tomcat7 ã«ãããã¤ãããæã¯
$ mvn package
ããã° target ã®ä¸ã« servlet-test.war ãçæãããã®ã§ãããæ¾ãè¾¼ãã°ok