2013년 8월 17일 토요일

Maven 빌드 플러그인 사용하기 - Jetty 빌드 플러그인

Jetty 빌드 플러그인은 http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html를 참고합니다. (Maven 빌드 플러그인 전반적인 내용은 http://maven.apache.org/plugins/를 참고합니다.)
!주의 : You need to use Maven 3 and Java 1.7 for this plugin.

<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${project.version}</version>


여기서는 이클립스 프로젝트 사이트로 옮기기 전의 http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin 사이트 내용을 기준으로 합니다.

<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>


1. pom.xml을 수정합니다.


C:\Users\kdyoung\web\mywebapp\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>org.samples.maven</groupId>
  <artifactId>mywebapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>mywebapp</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
      </plugin>
    </plugins>
  </build>
</project>
-----------------------------------------------------------------------------------------------------------

2. jetty를 실행합니다.


-> C:\Users\kdyoung\web\mywebapp>mvn jetty:run

[INFO] Configuring Jetty for project: mywebapp
[INFO] Webapp source directory = C:\Users\kdyoung\web\mywebapp\src\main\webapp
[INFO] web.xml file = C:\Users\kdyoung\web\mywebapp\src\main\webapp\WEB-INF\web.xml
[INFO] Classes = C:\Users\kdyoung\web\mywebapp\target\classes
[INFO] Logging to org.slf4j.impl.SimpleLogger(org.mortbay.log) via org.mortbay.log.Slf4jLog
[INFO] Context path = /mywebapp
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] Webapp directory = C:\Users\kdyoung\web\mywebapp\src\main\webapp
[INFO] Starting jetty 6.1.10 ...
[INFO] jetty-6.1.10
[INFO] No Transaction manager found - if your webapp requires one, please configure one.
[INFO] Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server

3. Jetty 서버가 실행된 것을 확인하고 mywebapp 사이트로 이동합니다.





4. JSP 파일을 수정하고 브라우저를 새로 고침하면 바로 확인됩니다.


C:\Users\kdyoung\web\mywebapp\src\main\webapp\index.jsp
-----------------------------------------------------------------------------------------------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World Updated!</h1>
    </body>
</html>
-----------------------------------------------------------------------------------------------------------



5. Java 클래스가 수정되면 동적으로 반영하기 위해서는 pom.xml을 수정합니다.


C:\Users\kdyoung\web\mywebapp\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>org.samples.maven</groupId>
  <artifactId>mywebapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>mywebapp</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
<configuration>
            <scanIntervalSeconds>5</scanIntervalSeconds>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
-----------------------------------------------------------------------------------------------------------



...

댓글 없음:

댓글 쓰기