Spring 을 쓰는이유가 여러가지 있겠지만 나같은 경우는 테스트의 편안함을 가장 큰 이유로 꼽는다.

그래서 테스트를 위한 spring 3.0 의 maven 기본 설정을 알아보도록 하자.

 

1. 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/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>net.cranix.project.otm</groupId>
 <artifactId>otm</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>overtimemanagement Maven Webapp</name>
 <url>http://maven.apache.org</url>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>3.0.4.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>commons-dbcp</groupId>
   <artifactId>commons-dbcp</artifactId>
   <version>1.4</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-jdbc</artifactId>
   <version>3.0.4.RELEASE</version>
  </dependency>

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-test</artifactId>
   <version>3.0.5.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>2.5</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>org.mockito</groupId>
   <artifactId>mockito-all</artifactId>
   <version>1.8.5</version>
   <scope>test</scope>
  </dependency>

 </dependencies>
 <build>
  <finalName>overtimemanagement</finalName>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <target>1.6</target>
     <source>1.6</source>
     <encoding>UTF-8</encoding>
    </configuration>

   </plugin>
  </plugins>
 </build>
</project>

 

 

 

 

2. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">
 <display-name>otm</display-name>

 <servlet>
  <servlet-name>otm</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>otm</servlet-name>
  <url-pattern>/main/*</url-pattern>
 </servlet-mapping>
</web-app>

 

 

 

 

3. otm-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
       
    <import resource="classpath:otm-springcontext.xml"/>

 
</beans>

- 테스트를 위해서는 WEB-INF 디렉토리에 설정파일을 두는것 보다는 classpath 상에 두는것이 낳다.

그렇기 때문에 위와같이 WEB-INF 디렉토리의 컨텍스트 파일에는 임포트만 하도록 한다.

 

 

4. otm-springcontext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

 <context:component-scan base-package="net.cranix.project.otm" />
 <bean id="viewResolver"
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/jsp/" />
  <property name="suffix" value=".jsp" />
 </bean>

</beans>

 

 

5. 테스트코드

package net.cranix.project.otm.controller;

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/otm-springcontext.xml")
public class MainControllerTest {
 @Autowired
 private MainController mainController = null;
 
 @Test
 public void testIndex() {
  String page = mainController.index();
 
  assertEquals("index",page);
 }

}

- 이와같이 셋팅하면 위와 같은 형태로 어노테이션 기반으로 스프링의 DI 를 쉽게 사용하여 테스트 할 수 있게된다.

 

 

언제나 생각한거지만 Spring 은 예술이다.

 

 

 

 

 

 

 

 

 

 

by cranix 2010. 10. 25. 22:49

1. 테스트를 위한 view 페이지를 만든다.

   - WEB-INF/jsp/dao.jsp 생성

<html>
<body>
<h2>data : ${data }</h2>
</body>
</html>


 

2. DAO 클래스 작성

   - package : net.cranix.web.hellospring3.dao

   - name : TestDAO

 

package net.cranix.web.hellospring3.dao;

public class TestDAO {
 private String data = null;
 public void setData(String data) {
  this.data = data;
 }
 public String getData() {
  return data;
 }
}

   - @Component 를 사용하지 않았기 때문에 bean 설정파일에 등록해 주어야 한다.

 

 

3. Controller 작성

   - package : net.cranix.web.hellospring3

   - name : DaoProcess

package net.cranix.web.hellospring3;

import net.cranix.web.hellospring3.dao.TestDAO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DaoProcess {
 public TestDAO testDAO = null;
 

// 스프링 bean 에 등록되어있는 컴포넌트를 자동으로 입력해 준다.

// 이것으로 이 파일에대한 bean 등록을 하지않아도 된다.
 @Autowired
 public void setTestDAO(TestDAO testDAO) {
  this.testDAO = testDAO;
 }
 
 @RequestMapping("dao")
 public String dao(Model model) {
  model.addAttribute("data",testDAO.getData());
  return "dao";
 }
 
}

 

 

4. bean 설정파일 수정

    - WEB-INF/hello-servlet.xml

<beans ...>
...
 <bean id="testDAO" class="net.cranix.web.hellospring3.dao.TestDAO">
  <property name="data" value="daodata!!"/>
 </bean>
</beans>

   - 결국 실제 string 은 이 설정파일에서 넣어준다.

 

 

5. 실행해보기

   - http://localhost:8080/hellospring3/dao.do 접근

 

 

6. 마무리

   - 사실 스프링 내에서 관리되는 모든 bean 들은 어노테이션을 추가하면 xml 설정을 하지않아도 되게 되어있다. 그러나 dao 같이 connection pool 을 가지고 있어야 하는 모듈 들은 위와 같이 해서 connection 정보를 xml 파일에 저장하는것이 효율적인 방법이다.

 

' > Spring' 카테고리의 다른 글

maven Spring3.0 webmvc 기본설정  (63) 2010.10.25
Spring 3.0 webmvc 의 request 를 처리하는 8가지 방법  (844) 2010.09.29
Spring 3.0 webmvc heloworld!!!  (31) 2010.09.29
Spring 에서 JUnit 로 테스트하기  (733) 2007.06.10
이거 이해가 안된다.  (64) 2007.06.09
by cranix 2010. 9. 29. 18:13

1. 결과를 뿌려주기위해 jsp 를 먼저 만든다.

    - WEB-INF/jsp/request/request.jsp 생성

<html>
<body>
<h2>request</h2>
</body>
</html>


   - WEB-INF/jsp/request/request2.jsp 생성

<html>
<body>
<h2>message : ${message }</h2>
</body>
</html>

 


2. RequestProcess 클래스 생성

   - package : net.cranix.web.hellospring3

   - className : RequestProcess

 

package net.cranix.web.hellospring3;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

 

// 클래스에 @RequestMapping 어노테이션을 쓰면 상위 URL 이 추가된다.

// http://localhost:8080/hellospring3/request/... 형태로 접근해야 한다.
@Controller
@RequestMapping("request")
public class RequestProcess {


// return void 이면 request 와 같은 경로의 view 를 자동으로 찾는다.

// http://localhost:8080/hellospring3/request/request.do 로 접근
 @RequestMapping("request")
 public void request1() {
 }
 
 
// return string 이면 해당 값의 view 를 찾는다.

// http://localhost:8080/hellospring3/request/request2.do 로 접근
 @RequestMapping("request2")
 public String request2() {
  return "request/request";
 }
 
 
// parameter 가 있으면 파라미터를 받는다.
// 만약 파라메터를 프리미티브 타입으로 해 놓으면 넘기지 않으면 오류난다.
// 그럼으로 파라메터는 왠만하면 Wrapper 타입으로 써줘야 한다.

// http://localhost:8080/hellospring3/request/request3.do?param1=aa&param2=2 로 접근
 @RequestMapping("request3")
 public String request3(String param1,Integer param2) {
  System.out.println("param1:"+param1+",param2:"+param2);

  return "request/request";
 }
 

// @RequestParam 어노테이션으로 파라메터의 좀 더 세세한 설정이 가능하다.

// http://localhost:8080/hellospring3/request/request4.do?p1=aa&p2=2 로 접근
 @RequestMapping("request4")
 public String request4(
   @RequestParam(value="p1",required=true) String param1,
   @RequestParam(value="p2",required=true) Integer param2
   ) {
  System.out.println("param1:"+param1+",param2:"+param2);

  return "request/request";
 }
 
 
// 파라메터에 Model 객체를 넣어놓으면 해당 객체에 속성을 추가하는것으로 view 에 데이터를 던져 줄 수 있다.

// http://localhost:8080/hellospring3/request/request5.do 로 접근
 @RequestMapping("request5")
 public String request5(Model model) {
  model.addAttribute("message","hello5");
  return "request/request2";
 }
 
// 리턴을 ModelAndView 를 받는것으로 view 에 데이터를 던져 줄 수도 있다.

// http://localhost:8080/hellospring3/request/request6.do? 로 접근
 @RequestMapping("request6")
 public ModelAndView request6() {
  ModelAndView modelAndView = new ModelAndView();
  modelAndView.setViewName("request/request2");
  modelAndView.getModel().put("message","hello6");

  return modelAndView;
 }
 
 
// 파라메터와 model 을 혼용해서 사용할 수 있다.

// http://localhost:8080/hellospring3/request/request7.do?param1=aa&param2=2 로 접근
 @RequestMapping("request7")
 public String request7(String param1,Integer param2,Model model) {
  System.out.println("param1:"+param1+",param2:"+param2);
  model.addAttribute("message","hello7");

  return "request/request2";
 }
 
// 마찬가지로 파라메터와 ModelAndView 를 같이 사용할수 있다.

// http://localhost:8080/hellospring3/request/request8.do?param1=aa&param2=2 로 접근
 @RequestMapping("request8")
 public ModelAndView request8(String param1,Integer param2) {
  System.out.println("param1:"+param1+",param2:"+param2);
  ModelAndView modelAndView = new ModelAndView();
  modelAndView.setViewName("request/request2");
  modelAndView.getModel().put("message","hello8");

  return modelAndView;
 }
}

 

 

3. 마무리

   - 어떤 방식을 쓰던 개발자의 자유다. 역시 스프링답게 상당히 프리하게 풀어놨다.

 

 

 

 

 

by cranix 2010. 9. 29. 17:33

1. eclipse 에서 Maven Project 생성

    - archetype :

        - Group Id : org.apache.maven.archetypes

        - Artifact Id : maven-archetype-webapp

    - group Id : net.cranix.web

    - artifact Id : hellospring3

 

 

2. maven dependency 에 spring-mvc 추가

    - 기본 웹 archetype 을 선택했기때문에 spring-webmvc 라이브러리를 추가해 줘야한다.

    - 그리고 기본적으로 메이븐 플러그인에서 이클립스 버젼을 관리하도록 아래와 같이 버젼셋팅 플러그인을 추가한다.

    - pom.xml 파일에 아래 추가

<dependencies>
...
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>3.0.4.RELEASE</version>
  </dependency>
</dependencies>
<build>
...
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <target>1.6</target>
     <source>1.6</source>
    </configuration>
   </plugin>
  </plugins>
</build>

    - Maven -> Update Project Configuration 로 프로젝트 설정 업데이트

    - 플러그인 설정을 하지않으면 기본적으로 1.5 이하버젼으로 셋팅되기때문에 어노테이션을 쓸 수가 없음으로 주의하자.

 


3. 프로젝트에 java 소스디렉토리 추가

   - 처음 만들면 java 소스 폴더가 없기때문에 만들어주자.

   - New > Source Folder

       - Folder name : src/main/java

 

 

4. 톰켓 작동 테스트

   - Run As -> Maven build...

      - Goals : tomcat:run

   - http://localhost:8080/hellospring3/ 접속확인

 

 

5. WEB-INF/web.xml 파일수정

   - 톰켓으로 들어오는 요청을 spring-webmvc 로 돌리기 위해서 셋팅을 해야한다.

   - *.do 로 들어오는 모든 요청을 spring 이 처리하도록 한다.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">
 
 <display-name>Archetype Created Web Application</display-name>
 
 <servlet>
  <servlet-name>hello</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 </servlet>
 
 <servlet-mapping>
  <servlet-name>hello</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>
 
</web-app>

    - 기본적인 web.xml 파일은 jsp 버젼을 2.3 을 채택하고 있기때문에 위 처럼 버젼을 2.4 로 바꾸지 않으면 jsp 의 EL 표현식을 사용할 수 없으니 주의하자.

 

 

6. spring bean 설정파일 만들기

    - spring bean 설정파일 이름은 [servlet-name]-servlet.xml 형태로 만들어야 한다.

    - WEB-INF/hello-servlet.xml 파일 생성해서 아래와 같이 입력하자.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">


 <context:component-scan base-package="net.cranix.web.hellospring3" />
 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/jsp/" />
  <property name="suffix" value=".jsp" />
 </bean>
 
</beans>

    - context:component-scan 태그는 이름그대로 어노테이션 기반의 spring3-mvc 컴포넌트를 검색하도록 하기위한 기본 패키지를 지정한다. 여기에 지정된 패키지는 하위 패키지까지 자동으로 검색해서 컴포넌트를 등록해 준다.

    - spring-webmvc 는 id 가 viewResolver 인 bean 을 가지고 출력할 view 페이지의 경로를 만들어 낸다.

 

7. hello jsp 만들기

   - WEB-INF/jsp/hello.jsp 생성 (jsp 디렉토리도 생성)

<html>
<body>
<h2>hello ${message}</h2>
</body>
</html>


 

8. hello controller 만들기

   - New -> Class

      - Package : net.cranix.web.hellospring3

      - Name : Hello

 

package net.cranix.web.hellospring3;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class Hello {
 @RequestMapping("hello")
 public String hello(Model model) {
  model.addAttribute("message","spring3!!");
  return "hello";
 }
}


9. 실행하기

   - Run As -> Maven build...

      - Goals : tomcat:run

   - http://localhost:8080/hellospring3/hello.do 접속확인

 

 

10. 마무리

  - 스프링3.0 webmvc 모델은 어노테이션 지원을 강화했다. 거의 xml 편집을 하지않아도 될 정도이기 때문에 상당히 편해졌음을 알 수 있다.

 

by cranix 2010. 9. 29. 16:18

플러그인 개발을 시작하려고 하는데 Extensions 의 새로만들기에 Generic 밖에 없어서 생성이 안될때 아래와 같은 플러그인을 설치하면 된다.

 

image

 

그리고 확인해 보면 아래와 같이 새로 생성이 되는것을 알 수 있다.

image

' > Eclipse' 카테고리의 다른 글

ECLIPSE 설정정보  (718) 2007.07.29
ECLIPSE 에서 ANT FTP 사용하기.  (21) 2007.07.28
by cranix 2009. 12. 28. 19:34

maven-jetty-plugin 포트 설정하기

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.20</version>
    <configuration>
        <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                <port>8081</port>
            </connector>
        </connectors>
    </configuration>           
</plugin>

 

 

참고사이트

http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

by cranix 2009. 9. 3. 13:19

maven-compiler-plugin encoding 설정하기

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

 

 

maven-resources-plugin encoding 설정하기

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

 

 

메이븐에서는 위와같이 버젼이며 인코딩을 명시해 줘야한다. 안그러면 알수없는 오류들을 내뱉는 경우가 종종있다.

by cranix 2009. 9. 3. 12:16

서론

날자 컨트롤 하는 부분은 간단하면서도 복잡하다. mysql 에서 지원하는 아래 함수들로 날자 연산을 쉽게 할 수 있다.

 

 

본론

DATE_ADD(date,INTERVAL expr  unit), DATE_SUB(date,INTERVAL expr  unit)

함수의 기본형은 위와 같고 INTERVAL 키워드의 형태는 아래와 같이 쓰인다.

unit Value 형태
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS

SECOND_MICROSECOND

'SECONDS.MICROSECONDS'

MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH

'YEARS-MONTHS'

 

위에서 지원되는 DATE_ADD, DATE_SUB 함수는 사용자 편의를 위해 +,- 연산자 형태로도 사용할 수 있다. 아래 와 같은 형태로 사용 될 수 있다.

mysql> SELECT '2008-12-31 23:59:59' + INTERVAL 1 SECOND;
        -> '2009-01-01 00:00:00'
mysql> SELECT INTERVAL 1 DAY + '2008-12-31';
        -> '2009-01-01'
mysql> SELECT '2005-01-01' - INTERVAL 1 SECOND;
        -> '2004-12-31 23:59:59'
mysql> SELECT DATE_ADD('2000-12-31 23:59:59',
    ->                 INTERVAL 1 SECOND);
        -> '2001-01-01 00:00:00'
mysql> SELECT DATE_ADD('2010-12-31 23:59:59',
    ->                 INTERVAL 1 DAY);
        -> '2011-01-01 23:59:59'
mysql> SELECT DATE_ADD('2100-12-31 23:59:59',
    ->                 INTERVAL '1:1' MINUTE_SECOND);
        -> '2101-01-01 00:01:00'
mysql> SELECT DATE_SUB('2005-01-01 00:00:00',
    ->                 INTERVAL '1 1:1:1' DAY_SECOND);
        -> '2004-12-30 22:58:59'
mysql> SELECT DATE_ADD('1900-01-01 00:00:00',
    ->                 INTERVAL '-1 10' DAY_HOUR);
        -> '1899-12-30 14:00:00'
mysql> SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
        -> '1997-12-02'
mysql> SELECT DATE_ADD('1992-12-31 23:59:59.000002',
    ->            INTERVAL '1.999999' SECOND_MICROSECOND);
        -> '1993-01-01 00:00:01.000001'

 

 

결론

날자 연산에서 +,- 연산자의 지원으로 정말 편리하게 연산할 수 있게 되었다.

' > Mysql' 카테고리의 다른 글

MYSQL 글자 붙이기  (44) 2007.07.23
MYSQL LAST_INSERT_ID()  (26) 2007.07.20
MYSQL JOIN 구문  (1087) 2007.06.10
MYSQL EUC-KR 을 UTF-8 로 변경하기  (682) 2007.03.09
MYSQL 유용한 명령어들  (26) 2006.12.18
by cranix 2009. 8. 19. 17:03

들어가며

기존에 eclipse 에서 tomcat 프로그래밍을 하려면 톰켓을 받아서 설치해야 했었다. maven 에서는 어떻게 하는지 확인해 보도록 하자.

 

프로젝트 만들기

이번 프로젝트는 웹 어플리케이션 이기 때문에 배포형태를 war 로 한다.

 

 

 

디렉토리 구조

웹 어플리케이션 형태는 위와 같이 webapp 디렉토리가 추가된 것이 보일 것이다. 여기에 웹 파일들을 위치시키면 된다.

 

 

TOMCAT 플러그인 설치

이제 웹 어플리 케이션을 테스트 하기 위해서 tomcat 플러그인을 설치해야 한다. tomcat 플러그인은 이름에서도 알 수 있듯이 maven 웹 어플리케이션을 편리하게 tomcat 으로 테스트 해 볼 수 있게 해 주는 플러그인이다. 

 

설치하기 위해서는 아래와 같이 pom.xml 파일을 열어서 plugins 탭에 Add Plugin 아이콘을 클릭한다.

 

아래와 같은 검색화면이 나오는데 tomcat 으로 검색해서 추가하자.

 

 

HELLO 실행하기

일단 아래와 같은 index.jsp 파일을 webapp 디렉토리에 추가하자.

 

- main/webapp/index.jsp

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

 

 

이제 위에서 받은 톰켓 플러그인을 실행해 주면 되는데 그 방법은 [Run As]-[maven build…] 를 클릭 한다음 아래와 같이 Goals 에다가 tomcat:run 이라고 입력하고 Run 을 누르면 된다.

 

그러면 Console 창에 메시지가 뜨면서 실행을 하게 되는데 만약 톰켓이 없다면 자동으로 로컬 레포지토리에 받아지게 된다. 다 받아진 후에 아래 메시지가 뜨면서 실행된다.

[INFO] [tomcat:run {execution: default-cli}]
[INFO] Running war on http://localhost:8080/simplewebapp
[INFO] Creating Tomcat server configuration at D:\cranix\work\workspace-wtp2\simplewebapp\target\tomcat
2009. 8. 17 오후 10:15:47 org.apache.catalina.startup.Embedded start
정보: Starting tomcat server
2009. 8. 17 오후 10:15:48 org.apache.catalina.core.StandardEngine start
정보: Starting Servlet Engine: Apache Tomcat/6.0.16
2009. 8. 17 오후 10:15:48 org.apache.coyote.http11.Http11Protocol init
정보: Initializing Coyote HTTP/1.1 on http-8080
2009. 8. 17 오후 10:15:48 org.apache.coyote.http11.Http11Protocol start
정보: Starting Coyote HTTP/1.1 on http-8080

 

이제 위에서 나온 주소로 접속해 보면 아래와 같이 제대로 뜨는 것을 확인 할 수 있다.

 

 

마치며

maven 은 tomcat 조차도 플러그인 형태로 취급한다. 이렇게 함으로서 작업환경을 특정 플랫폼에 종속시키지 않을 수 있을 것이다.

' > maven' 카테고리의 다른 글

maven-jetty-plugin 포트 설정하기  (3291) 2009.09.03
maven 에서 encoding 설정하기  (844) 2009.09.03
eclipse 에서 간단한 maven 프로젝트 만들기 (create 에서 assembly 까지)  (49) 2009.08.16
eclipse 에서 maven  (755) 2009.08.16
maven 이란  (37) 2009.08.15
by cranix 2009. 8. 17. 22:24

들어가며

이 글은 아래 사이트의 내용을 기초로하여 만들어 졌다. 아래 사이트와 다른점은 한글이라는점과 이클립스가 들어갔다는 점이다. 아래에서 만드는 소스내용도 똑같으니 참고하기 바란다.

http://www.sonatype.com/books/maven-book/reference/public-book.html

여기서 만드는 예제는 yahoo 에서 제공하는 xml 을 이용하여 날씨를 얻어오는 예제이다.

물론 프로젝트 내용은 중요한것이 아니고 maven의 기능을 살펴보는데 초점을 맞추게 될것이다.

 

 

프로젝트 만들기

maven 프로젝트를 생성해서 아래와같이 입력하고 Next 버튼을 누른다.

 

기본적으로 test 를 위해 junit 은 필요할테니까 Add 를 클릭해서 junit 을 검색해서 추가한다.

단 scope 는 test 로 해야 한다는 것을 잊지 말자.

 

 

Dependency 추가

pom.xml 파일을 열면 아래와같은 화면이 나오는데 여기서  Dependencies 탭으로 가서 아래처럼 찾기 아이콘을 클릭한다.

 

이제 찾기 화면에서 아래 라이브러를 검색해서 추가한다.  (단 여기서 log4j 는 이보다 최신버젼이 있지만 그 버젼을 선택할경우 오류가 나는 현상이 있어서 이전 버젼을 선택했다.) 추가한 다음에는 꼭 저장버튼을 클릭해서 적용을 하자.

log4j (1.2.14 )

dom4j

jaxen

velocity

 

 

프로그램 작성

프로그램 작성에 들어가기 전에 이클립스 셋팅을 해야한다. maven 프로젝트를 생성하면 기본적으로 자바 1.4 가 선택이 된다. 프로젝트의 Properties 로 들어가서 Java Compiler 메뉴로 가서 컴파일러 버젼을 최신으로 바꾼다음에 진행하도록 하자.

 

프로그램의 소스파일은 아래와 같다. 여기서 중요한 것은 소스의 내용이 아니기 때문에 소스설명은 생략하도록 하겠다.

net/cranix/Weather.java

net/cranix/Main.java

net/cranix/YahooRetriver.java

net/cranix/YahooParser.java

net/cranix/WeatherFormatter.java

 

<net/cranix/Weather.java>

package net.cranix;

public class Weather {
    private String city;
    private String region;
    private String country;
    private String condition;
    private String temp;
    private String chill;
    private String humidity;

    public Weather() {
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCondition() {
        return condition;
    }

    public void setCondition(String condition) {
        this.condition = condition;
    }

    public String getTemp() {
        return temp;
    }

    public void setTemp(String temp) {
        this.temp = temp;
    }

    public String getChill() {
        return chill;
    }

    public void setChill(String chill) {
        this.chill = chill;
    }

    public String getHumidity() {
        return humidity;
    }

    public void setHumidity(String humidity) {
        this.humidity = humidity;
    }
}

 

<net/cranix/Main.java>

package net.cranix;

import java.io.InputStream;

import org.apache.log4j.PropertyConfigurator;

public class Main {

    public static void main(String[] args) throws Exception {
        // Configure Log4J
        PropertyConfigurator.configure(Main.class.getClassLoader().getResource("log4j.properties"));

        // Read the Zip Code from the Command-line (if none supplied, use 60202)
        String zipcode = "60202";
        try {
          zipcode = args[0];
        } catch( Exception e ) {}

        // Start the program
        new Main(zipcode).start();
      }

    private String zip;

    public Main(String zip) {
        this.zip = zip;
    }

    public void start() throws Exception {
        // Retrieve Data
        InputStream dataIn = new YahooRetriever().retrieve(Integer.valueOf(zip));

        // Parse Data
        Weather weather = new YahooParser().parse(dataIn);

        // Format (Print) Data
        System.out.print(new WeatherFormatter().format(weather));
    }
}

<net/cranix/YahooRetriver.java>

package net.cranix;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.log4j.Logger;

public class YahooRetriever {

    private static Logger log = Logger.getLogger(YahooRetriever.class);

    public InputStream retrieve(int zipcode) throws Exception {
        log.info("Retrieving Weather Data");
        String url = "http://weather.yahooapis.com/forecastrss?p=" + zipcode;
        URLConnection conn = new URL(url).openConnection();
        return conn.getInputStream();
    }
}

<net/cranix/YahooParser.java>

package net.cranix;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.io.SAXReader;

public class YahooParser {

    private static Logger log = Logger.getLogger(YahooParser.class);

    public Weather parse(InputStream inputStream) throws Exception {
        Weather weather = new Weather();

        log.info("Creating XML Reader");
        SAXReader xmlReader = createXmlReader();
        Document doc = xmlReader.read(inputStream);

        log.info("Parsing XML Response");
        weather.setCity(doc.valueOf("/rss/channel/y:location/@city"));
        weather.setRegion(doc.valueOf("/rss/channel/y:location/@region"));
        weather.setCountry(doc.valueOf("/rss/channel/y:location/@country"));
        weather.setCondition(doc.valueOf("/rss/channel/item/y:condition/@text"));
        weather.setTemp(doc.valueOf("/rss/channel/item/y:condition/@temp"));
        weather.setChill(doc.valueOf("/rss/channel/y:wind/@chill"));
        weather.setHumidity(doc.valueOf("/rss/channel/y:atmosphere/@humidity"));

        return weather;
    }

    private SAXReader createXmlReader() {
        Map<String, String> uris = new HashMap<String, String>();
        uris.put("y", "http://xml.weather.yahoo.com/ns/rss/1.0");

        DocumentFactory factory = new DocumentFactory();
        factory.setXPathNamespaceURIs(uris);

        SAXReader xmlReader = new SAXReader();
        xmlReader.setDocumentFactory(factory);
        return xmlReader;
    }
}

<net/cranix/WeatherFormatter.java>

package net.cranix;

import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;

import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class WeatherFormatter {
    private static Logger log = Logger.getLogger(WeatherFormatter.class);
    public String format(Weather weather) throws Exception {
        log.info("Formatting Weather Data");
        Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("output.vm"));
        VelocityContext context = new VelocityContext();
        context.put("weather", weather);
        StringWriter writer = new StringWriter();
        Velocity.evaluate(context, writer, "", reader);
        return writer.toString();
    }
}

 

소스를 조금 설명하자면 dom4j 라이브러리로 yahoo 에서 제공하는 xml 파일을 읽어서 파싱한 다음 velocity 라이브러리로 출력을 하게 되는 것이다. 여기서 콘솔출력은 log4j 에 의해 이루어진다.

 

 

RESOURCE 추가

그러나 이렇게 소스만 만들어놨다고 제대로된 결과를 기대하기는 어렵다. 왜냐하면 log4j 같은 경우는 설정 파일이 필요하고 velocity 는 템플릿 파일이 필요하다 이런 resource 를 추가하는 방법을 알아보도록 하겠다.

 

모든 리소스들은 resource 디렉토리에 위치시키면 된다. 이 프로그램에서 필요한 리소스는 아래와 같다.

log4j.properties

output.vm

 

<log4j.properties>

# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r %-5p %c{1} %x - %m%n

<output.vm>

*********************************
Current Weather Conditions for:
${weather.city}, ${weather.region}, ${weather.country}

Temperature: ${weather.temp}
Condition: ${weather.condition}
Humidity: ${weather.humidity}
Wind Chill: ${weather.chill}
*********************************

디렉토리의 형태는 아래와 같다.

 

 

실행하기

실행하기 위해서는 Run As-maven build 를 클릭한다음 아래와같이 셋팅하고 Run 을 클릭하자.

 

아래와 같은 결과가 나오면서 우리가 만든 프로그램이 제대로 실행되고 있는 것을 알 수 있다.

[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] Attempting to resolve a version for plugin: org.codehaus.mojo:exec-maven-plugin using meta-version: LATEST
[INFO] Using version: 1.1.1 of plugin: org.codehaus.mojo:exec-maven-plugin
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - net.cranix:weather:jar:0.0.1-SNAPSHOT
[INFO]
[INFO] Id: net.cranix:weather:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] [exec:java]
0    INFO  YahooRetriever  - Retrieving Weather Data
359  INFO  YahooParser  - Creating XML Reader
561  INFO  YahooParser  - Parsing XML Response
639  INFO  WeatherFormatter  - Formatting Weather Data
*********************************
Current Weather Conditions for:
  Evanston, IL, US
Temperature: 70
   Condition: Fair
    Humidity: 73
  Wind Chill: 70
*********************************
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Sun Aug 16 15:44:18 KST 2009
[INFO] Final Memory: 4M/12M
[INFO] ------------------------------------------------------------------------

 

 

Dependency 정보 확인하기

이렇게 maven 으로 프로젝트를 만들었다면 Dependency 정보를 쉽게 확인할 수 있다.

pom.xml 파일을 열어서 Dependency Graph 탭을 클릭하고 새로고침 버튼을 클릭하면 아래와 같이 그래프 형태로 표시되는 것을 볼 수 있다.

 

아래와 같이 Dependency Hierarchy 를 클릭해서 트리 형태로 볼 수도 있다.

 

 

 

테스트 소스 추가하기

여기서는 유닛 테스트를 위해 commons-io 라이브러리를 사용한다. pom.xml 파일을 열어서 dependency 탭으로 가서 commons-io 라이브러리를 검색해서 추가하자. 단 테스트를 위한 것이기 때문에 scope 를 test 로 설정하자.

 

테스트를 하기 위해서는 test 디렉토리에 테스트 파일이 위치해야 하며 여기서 사용할 테스트파일은 아래와 같다.

test/net/cranix/YahooParserTest.java

test/net/cranix/WeatherFormatterTest.java

 

<test/net/cranix/YahooParserTest.java>

package net.cranix;

import java.io.InputStream;

import junit.framework.TestCase;

public class YahooParserTest extends TestCase {

    public YahooParserTest(String name) {
        super(name);
    }

    public void testParser() throws Exception {
        InputStream nyData = getClass().getClassLoader().getResourceAsStream(
                "ny-weather.xml");
        Weather weather = new YahooParser().parse(nyData);
        assertEquals("New York", weather.getCity());
        assertEquals("NY", weather.getRegion());
        assertEquals("US", weather.getCountry());
        assertEquals("39", weather.getTemp());
        assertEquals("Fair", weather.getCondition());
        assertEquals("39", weather.getChill());
        assertEquals("67", weather.getHumidity());
    }
}

 

<test/net/cranix/WeatherFormatterTest.java>

package net.cranix;

import java.io.InputStream;

import org.apache.commons.io.IOUtil;

import junit.framework.TestCase;

public class WeatherFormatterTest extends TestCase {

    public WeatherFormatterTest(String name) {
        super(name);
    }

    public void testFormat() throws Exception {
        InputStream nyData = getClass().getClassLoader().getResourceAsStream("ny-weather.xml");
        Weather weather = new YahooParser().parse(nyData);
        String formattedResult = new WeatherFormatter().format(weather);
        InputStream expected = getClass().getClassLoader().getResourceAsStream("format-expected.dat");
        assertEquals(IOUtil.toString(expected).trim(), formattedResult.trim());
    }
}

 

 

테스트 RESOURCE 추가하기

테스트를 위한 이 프로그램 역시 그냥은 실행되지 않는다. 리소스 파일을 추가해 줘야 하는데 테스트 리소스 파일은 test/resources 디렉토리에 위치해야 한다.

test/resources/format-expected.dat

test/resources/ny-weather.xml

<test/resources/format-expected.dat>

*********************************
Current Weather Conditions for:
New York, NY, US

Temperature: 39
Condition: Fair
Humidity: 67
Wind Chill: 39
*********************************
<test/resources/ny-weather.xml>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - New York, NY</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/New_York__NY/</link>
<description>Yahoo! Weather for New York, NY</description>
<language>en-us</language>
<lastBuildDate>Sat, 10 Nov 2007 8:51 pm EDT</lastBuildDate>

<ttl>60</ttl>
<yweather:location city="New York" region="NY" country="US" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:wind chill="39" direction="0" speed="0" />
<yweather:atmosphere humidity="67" visibility="1609" pressure="30.18"
rising="1" />
<yweather:astronomy sunrise="6:36 am" sunset="4:43 pm" />
<image>
<title>Yahoo! Weather</title>

<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com/</link>
<url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for New York, NY at 8:51 pm EDT</title>

<geo:lat>40.67</geo:lat>
<geo:long>-73.94</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/New_York__NY/\</link>
<pubDate>Sat, 10 Nov 2007 8:51 pm EDT</pubDate>
<yweather:condition text="Fair" code="33" temp="39"
date="Sat, 10 Nov 2007 8:51 pm EDT" />
<description><![CDATA[
<img src="http://l.yimg.com/us.yimg.com/i/us/we/52/33.gif" /><br />
<b>Current Conditions:</b><br />
Fair, 39 F<BR /><BR />
<b>Forecast:</b><BR />
Sat - Partly Cloudy. High: 45 Low: 32<br />
Sun - Sunny. High: 50 Low: 38<br />
<br />
]]></description>
<yweather:forecast day="Sat" date="10 Nov 2007" low="32" high="45"
text="Partly Cloudy" code="29" />

<yweather:forecast day="Sun" date="11 Nov 2007" low="38" high="50"
text="Sunny" code="32" />
<guid isPermaLink="false">10002_2007_11_10_20_51_EDT</guid>
</item>
</channel>
</rss>

 

최종 디렉토리는 아래와 같다.

 

 

 

테스트 실행

이제 테스트 환경이 갖추어졌다.

Run As-maven test 를 실행하자. 아래와 같이 테스트가 되는 것을 볼 수 있다.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - net.cranix:weather:jar:0.0.1-SNAPSHOT
[INFO]
[INFO] Id: net.cranix:weather:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory: D:\cranix\work\workspace-wtp2\weather\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running net.cranix.YahooParserTest
0    INFO  YahooParser  - Creating XML Reader
171  INFO  YahooParser  - Parsing XML Response
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.407 sec
Running net.cranix.WeatherFormatterTest
266  INFO  YahooParser  - Creating XML Reader
282  INFO  YahooParser  - Parsing XML Response
282  INFO  WeatherFormatter  - Formatting Weather Data
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.172 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Sun Aug 16 16:55:20 KST 2009
[INFO] Final Memory: 2M/6M
[INFO] ------------------------------------------------------------------------

 

 

 

Dependencies 까지 포함시켜서 패키징하기

이 과정을 assembly 과정 이라고 하는데 제대로 실행되도록 하려면 셋팅을 해야한다. pom.xml 파일을 열어서 아래 부분을 추가한다.

<project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>

 

그 다음 Run As-maven assembly:assembly 를 실행한다. 아래와같은 화면이 나오면서 패키징을 하게된다.

[INFO] [jar:jar]
[INFO] Building jar: D:\cranix\work\workspace-wtp2\weather\target\weather-0.0.1-SNAPSHOT.jar
[INFO] [statemgmt:end-fork]
[INFO] Ending forked execution [fork id: 574707759]
[INFO] [assembly:assembly]
[INFO] Processing DependencySet (output=)
[INFO] Expanding: D:\cranix\work\maven\repository\log4j\log4j\1.2.14\log4j-1.2.14.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.1429370463.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\maven\dom4j\1.7-20060614\dom4j-1.7-20060614.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.1955766376.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\jaxme\jaxme-api\0.3\jaxme-api-0.3.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.165260721.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\jaxen\jaxen\1.1.1\jaxen-1.1.1.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.1217840646.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.3570191.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\jdom\jdom\1.0\jdom-1.0.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.1685521809.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\xerces\xmlParserAPIs\2.6.2\xmlParserAPIs-2.6.2.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.305584397.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\xerces\xercesImpl\2.6.2\xercesImpl-2.6.2.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.1558042758.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\xom\xom\1.0\xom-1.0.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.2049563553.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\com\ibm\icu\icu4j\2.6.1\icu4j-2.6.1.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.796405737.tmp
[INFO] Expanding: D:\cranix\work\maven\repository\xalan\xalan\2.6.0\xalan-2.6.0.jar into C:\Users\cranix\AppData\Local\Temp\archived-file-set.1324133154.tmp

이 작업은 현재 종속된 모든 라이브러리를 하나의 jar 파일로 묶는 작업으로 시간이 조금 걸린다. 완료가 되면 target 디렉토리에 모든 종속된 라이브러리의 클래스가 포함된 weather-0.0.1-SNAPSHOT-jar-with-dependencies.jar 파일이 생성된 것을 볼 수있다.

 

마치며

왠만해서 pom.xml 파일을 직접 에디트 하지 않았으면 했지만 아직 m2eclipse 플러그인 에서는 비쥬얼하게 위와같이 assembly 설정을 할수있는 방법이 없는거 같다. 하여튼 마지막 assembly 과정은 maven 의 백미 라고 볼 수 있겠다.

' > maven' 카테고리의 다른 글

maven-jetty-plugin 포트 설정하기  (3291) 2009.09.03
maven 에서 encoding 설정하기  (844) 2009.09.03
eclipse maven 으로 tomcat 어플리케이션 만들기  (73) 2009.08.17
eclipse 에서 maven  (755) 2009.08.16
maven 이란  (37) 2009.08.15
by cranix 2009. 8. 16. 17:17
| 1 2 3 4 ··· 6 |