GWT with Maven

Posted at 2015. 3. 18. 02:31 | Posted in Framework
반응형

Installed the Java SDK


If you don’t have a recent version of the Java SDK installed, download and install Sun Java Standard Edition SDK.


적어도 이 문서를 찾아보는 이라면 자바는 이미 깔려 있을 것이라고 굳게 믿는다... -_-/




Installed Eclipse or your favorite Java IDE


In these tutorials, we use Eclipse because it is open source. However, GWT does not tie you to Eclipse. You can use IntelliJ, NetBeans or any Java IDE you prefer. If you use a Java IDE other than Eclipse, the screenshots and some of the specific instructions in the tutorial will be different, but the basic GWT concepts will be the same.


If your Java IDE does not include Apache Ant support, you can download and unzip Ant to easily compile and run GWT applications.


이클립스를 기준으로 한다. 현재 최신 버전인 Luna 로 하겠다.





Installed the Google Plugin for Eclipse


The Google Plugin for Eclipse adds functionality to Eclipse for creating and developing GWT applications.


구글 플러그인을 깔자.


Help - Install New Software...



Work with: https://dl.google.com/eclipse/plugin/4.4


항목중에 Google Plugin for Eclise 4.4 를 체크 - Next 버튼 클릭.





Using the Archetype


http://mojo.codehaus.org/gwt-maven-plugin/user-guide/archetype.html


메이븐 archetype 를 업데이트 해줘야 한다. (현재 최신 버전은 2.7.0 이다.)


File - New - Other...


Maven Project 선택.



gwt-maven 으로 필터링을 하게 되면 하나가 나오는데 버전이 2.5.0 일 것이다. (아래처럼 2.7.0 이라면 패스)


Add Archetype 버튼 클릭.



Archetype Group Id: org.codehaus.mojo

Archetype Artifact Id: gwt-maven-plugin

Archetype Version: 2.7.0 (현재의 최신 버전)



OK 버튼 클릭하면 archetype 을 다운로드해서 업데이트 한다.

아직 프로젝트는 안만들 것이니 Canel 버튼 클릭.




Creating the StockWatcher application (using Eclipse)


File - New  - Other... - Maven Project


Group Id: com.google.gwt.sample (아무거나 -_-)

Artifact Id: StockWatcher

Package: com.google.gwt.sample.stockwatcher

module: StockWatcher


※ 여기서 모듈명은 GWT 튜토리얼에 있는 StockWatcher 로 하겠다.



Finish 버튼 클릭.




Using the Google Eclipse Plugin


http://mojo.codehaus.org/gwt-maven-plugin/eclipse/google_plugin.html


메이븐을 이용해서 만들었는데 이클립스의 개발자 모드로 해보려면 추가 작업이 필요하다.


resources 쪽에 있는 gwt.xml 파일을 java 쪽으로 옮겨야한다.

구글 플러그인에서 resources 에 있는 gwt.xml 을 인식하지 못하는 것 같다.


src/main/resources/com/google/gwt/sample/stockwatcher 아래에 있는 StockWatcher.gwt.xml 파일을

com.google.gwt.sample.stockwatcher 패키지로 이동시킨다.



이동 결과



다음은 Google 플러그인 연결(?) 작업이다.


StockWatcher 프로젝트에서 오른쪽 버튼 클릭 - Properties



Google - Web Application


This project has a War directory 체크



Google - Web Toolkit


Use Google Web Toolkit 체크

Entry Point Modules 에 StockWatcher 가 등록되어 있다.



OK 버튼 클릭


※ OK 버튼 클릭 시 NullPointException 에러가 나면 취소 후 위 작업을 다시 해보자.




Testing the default project components


StockWatcher 프로젝트에서 오른쪽 버튼 클릭 - Run As - Web Application (GWT Super Dev Mode)



WAR 디렉토리를 선택하라고 최초에 한번 나올 것이다. src/main/webapp(기본) 를 선택하자.


앞으로 여기에 모든 파일들이 적용 된다. 라이브러리, 컴파일 되는 자바스크립트 파일 등등..



Console 창에 로그 출력 되다가 Development Mode 창에 아래와 같이 주소가 나오면 성공!



더블클릭 해서 브라우저를 띄워보자.



이제 GWT 로 "Hello World" 찍었다.


반응형
//

Installation Maven 3 on Ubuntu

Posted at 2014. 3. 25. 20:06 | Posted in Server/Ubuntu
반응형

출처 : http://stackoverflow.com/questions/5312350/where-is-maven-installed-on-ubuntu




우분투 버전 확인


# lsb_release -a

No LSB modules are available.

Distributor ID: Ubuntu

Description:    Ubuntu 12.04.4 LTS

Release:        12.04

Codename:       precise


설치


# add-apt-repository ppa:natecarlson/maven3

# apt-get update

# sudo apt-get install maven3


메이븐 버전 확인


# mvn3 -v

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T02:37:52+09:00)

Maven home: /usr/share/maven3

Java version: 1.7.0_51, vendor: Oracle Corporation

Java home: /usr/lib/jvm/java-7-oracle/jre

Default locale: ko_KR, platform encoding: UTF-8

OS name: "linux", version: "3.2.0-60-generic-pae", arch: "i386", family: "unix"



기본 명령어로 링크


# ln -s /usr/bin/mvn3 /usr/bin/mvn


반응형

'Server > Ubuntu' 카테고리의 다른 글

Disable automatic updates kernel on Ubuntu  (1) 2017.12.20
Installation Redmine on Ubuntu  (0) 2014.03.26
Using Xmanager to Ubuntu 10.10  (0) 2011.04.13
Subversion  (0) 2010.08.16
Openfire  (0) 2010.05.25
Webmin  (0) 2009.11.18
Squirrelmail  (0) 2009.11.12
SparkWeb  (0) 2009.11.12
Cacti  (0) 2009.11.12
Apache + SSL  (0) 2009.11.12
//

Javascript Dependency in Maven

Posted at 2014. 3. 19. 19:22 | Posted in JavaScript
반응형

http://www.webjars.org/


보통 메이븐을 통해서 자바 라이브러리(jar)들간의 의존 관계를 해결한다.


하지만 자바스크립트 라이브러리는 이런게 없다. 어디선가 js 파일 받아서 웹 소스에다가 놓고 써야한다.


예를 들어 "jQuery UI"를 써야 하면 jquery.ui.js 파일 받고 "jQuery UI"가 필요로 하는 jquery.js 를 구해서 넣어야한다.



<script type="text/javascript" src="js/static/jquery-1.11.0.min.js" ></script>

<script type="text/javascript" src="js/static/jquery-ui.min.js" ></script>


근데! 누군가가 메이븐으로 자바스크립트 라이브러리의 의존 관계를 관리할 수 있도록 했다.

이 기발한 원리는 이러하다. ㅋㅋ


1. /META-INF/ 안에 js 파일들을 넣은 jar 파일을 만들어서 메이븐으로 쓸 수 있도록 한다.

2. 프레임워크마다의 방법으로 classpath 안의 js 파일들을 웹상에서 쓸 수 있도록 한다.


pom.xml 에 아래와 같이 jquery-ui 를 추가하면


<dependency>

<groupId>org.webjars</groupId>

<artifactId>jquery-ui</artifactId>

<version>1.10.3</version>

</dependency>


아래와 같이 jquery 까지 다운로드 받게 된다.



실제 jar 내용을 보면 아래와 같이 js 와 관련된 파일들이 들어있다. (requireJS도? 들어있네 ㄷㄷ)



Spring 3의 mvc 네임스페이스를 이용하면 쉽게 설정 가능하다. (다른 방법은 http://www.webjars.org/documentation 참조)


<mvc:resources mapping="/js/static/**" location="classpath:/META-INF/resources/webjars/" />


html 에서는 리소스의 경로에 맞게 해주면 되겠다.


<script type="text/javascript" src="js/static/jquery/1.9.1/jquery.min.js" ></script>

<script type="text/javascript" src="js/static/jquery-ui/1.10.3/ui/minified/jquery-ui.min.js" ></script>


web-jars.war

 ↑ 소스 포함 war


web-jars.zip

 ↑ 이클립스 메이븐 프로젝트


반응형

'JavaScript' 카테고리의 다른 글

url 파라미터 알아내기  (5) 2010.01.15
//
반응형

Intorduction


http://www.juso.go.kr


- 도로명 주소는 2014년부터 생활(법정)주소로 전면 사용됩니다.

- 도로명주소를 사용하지 않으면 은행, 카드, 보험 등 거래처의 우편물 수신에 불편함이 있을 수 있습니다.


이렇게 나와있다... Y2K[각주:1] 처럼 버그도 아니고, 그냥 체계가 바뀌는 거지만... 미리 준비하자. -_-/




데이터 입력


http://www.juso.go.kr


정보제공 게시판 쪽에 가보면 현재 11월 기준의 도로명 주소 데이터가 올라와 있다. 매월 말에 데이터가 갱신 되는듯 하다... ㅅㅂ



4개의 게시글 첨부파일을 다 다운로드 받은 후 txt 파일이 나올때까지 전부 압축을 해제하자.


 

도로명주소정보제공내용변경계획.hwp


파일을 보면 알겠지면 4개의 테이블 구조로 되어있다. 이것을 대충 ERD로 짜보면 아래와 같다. 네이밍 ㅅㅂ -_-/


road.txp


01


이제 텍스트 파일에서 테이블로 데이터를 넣어야 한다.


근데 이게 많은 양의 데이터라서 툴을 이용해서 넣기 번거로으므로 Java 로 만들어서 넣었다 -_-;; (템플릿 메소드 패턴 이용!)


 레이아웃

 건수

 설명

 도로명코드 (tbl_road)

356.792 

 시도 시군구 읍면동 도로명

 주소 (tbl_road_addr)

5,976,050 

 도로명코드 x 건물본번-건물부번

 지번 (tbl_addr_jibun)

7,943,977 

 주소에 해당하는 지번(옛날) 주소 (주소에 해당하는 지번 주소는 n 건)

 부가정보 (tbl_addr_info)

5,976,050 

 주소에 해당하는 부가정보 (우편번호가 여기에 있다)


zipcode.reader.zip


↑ 메이븐 프로젝트이다.




데이터 조회


안전행정부에서 도로명 주소를 검색해 가면서 분석한 결과 아래와 같은 공식(?)이 나왔다. 


 구분

 공식

 도로명 주소

 #도로명코드.시도명# [#도로명코드.시군구명#] #도로명코드.도로명# [#주소.지하여부#=="1"?"지하"]

 #주소.건물번호본번#[-#주소.건물번호부번#!="0"?#주소.건물번호부번#]

 [(#도로명코드.읍면동명#[, #부가정보.공동주택여부#=="1"?#부가정보.시군구건물명#])]

 도로명 주소 영문

 [#주소.지하여부#=="1"?"Jiha, "] #주소.건물번호본번#[-#주소.건물번호부번]

 [, #도로명코드.읍면동명영문#] [, #도로명코드.시군구명영문#], #도로명코드.시도명영문#

 지번 주소 (~2013 주소)

 #지번.시도명# #지번.시군구명# [#지번.법정읍면동명#] [#지번.법정동명#] [#지번.법정리명#]

 [#지번.산여부#=="1"?"산"] [#지번.지번본번#[-#지번.지번부번#]] [#부가정보.시군구건물명#]


음.. 어렵다.. -_-... 위 3개의 경우를 쿼리(오라클)로 뽑아보면 아래와 같다. 쿼리로 보는게 더 편할지도? ㅋㅋ


select /* 우편번호 */ t3.zipcode as zipcode /* 도로명 주소 */ , t1.sido_name || case when t1.sigun_name is not null then ' ' || t1.sigun_name end || ' ' || t1.road_name || decode(t2.base_yn, '1', ' ' || '지하') || ' ' || t2.bldg_no1 || case when t2.bldg_no2 != 0 then '-' || t2.bldg_no2 end || ' (' || t1.eup_name || case when t3.apt_yn = '1' and t3.sigun_bldg_name is not null then ', ' || t3.sigun_bldg_name end || ')' as address /* 도로명 주소 영문 */ , decode(t2.base_yn, '1', 'Jiha' || ' ') || t2.bldg_no1 || case when t2.bldg_no2 != 0 then '-' || t2.bldg_no2 end || ', ' || t1.road_name_eng || case when t1.sigun_name_eng is not null then ', ' || t1.sigun_name_eng end || ', ' || t1.sido_name_eng as address_eng /* 지번 주소 (~2013 주소) */ , t4.sido_name || case when nvl(t4.gugun_name, t1.sigun_name) is not null then ' ' || nvl(t4.gugun_name, t1.sigun_name) end || case when nvl(t4.eup_name, t1.eup_name) is not null then ' ' || nvl(t4.eup_name, t1.eup_name) end || case when t4.ri_name is not null then ' ' || t4.ri_name end || decode(t4.san_yn, '1', '산') || ' ' || t4.ji_no1 || case when t4.ji_no2 != 0 then '-' || t4.ji_no2 end || case when t3.sigun_bldg_name is not null then ' ' || t3.sigun_bldg_name end as address_jibun

/* 관리번호(PK) */ , t2.num from tbl_road t1 join tbl_road_addr t2 on t1.road_code = t2.road_code and t1.eup_seq = t2.eup_seq join tbl_road_info t3 on t2.num = t3.num join tbl_road_jibun t4 on t2.num = t4.num where t1.using_yn = '0' and t4.dele_yn = '1' and to_char(sysdate, 'YYYYMMDD') between nvl(t1.noti_date, '11110101') and nvl(t1.cancel_date, '99991231') and to_char(sysdate, 'YYYYMMDD') >= nvl(t2.noti_date, '11110101') ;


뭐 보면 대충 이렇게 나온다.





데이터 가공


데이터의 양이 너무 많다. 4개의 테이블만 덤프를 떠도 1.8GB 정도 한다.


내가 이 도로명주소 데이터를 뽑는 이유는 우편번호를 사용하기 위함이기 때문에 필요없는거 다 날리고 다른 테이블에 다시 넣어보자.


아래 ERD 는 도로명 주소를 표현할 수 있는 최소한의 데이터만 사용했을 때의 테이블이다.


zipcode_road.txp



아래는 insert select 문이다.


insert into zipcode_road (
	zipcode
    , road
    , sido
    , sigun
    , eup
    , under_yn
    , bldg_no1
    , bldg_no2
    , bldg
    , num
    , apply_date
)
select
	t3.zipcode
    , t1.road_name
	, t1.sido_name
    , t1.sigun_name
    , t1.eup_name
	, decode(t2.base_yn, '1', 'Y', 'N') as under_yn
    , t2.bldg_no1
    , decode(t2.bldg_no2, 0, null, t2.bldg_no2) as bldg_no2
    , case when t3.apt_yn = '1' and t3.sigun_bldg_name is not null then t3.sigun_bldg_name end as bldg
    , t2.num
    , to_char(sysdate, 'YYYYMMDD') as apply_date
from
	tbl_road t1
join
	tbl_road_addr t2
on
	t1.road_code = t2.road_code
    and t1.eup_seq = t2.eup_seq
join
	tbl_road_info t3
on
	t2.num = t3.num
where
	t1.using_yn = '0'
	and to_char(sysdate, 'YYYYMMDD') between nvl(t1.noti_date, '11110101') and nvl(t1.cancel_date, '99991231')
	and to_char(sysdate, 'YYYYMMDD') >= nvl(t2.noti_date, '11110101')
;


이렇게 넣으니 데이터는 5,975,824건에 650MB 정도 된다. 이래도 많다... 예전 우편번호는 5만건 정도밖에 안되는데 ㅜㅜ




Web Application


이 데이터를 기반으로 조회하는걸 한번 만들어 봤다.


http://antop.nerv.kr/zipcode


zipcode.war


zipcode.zip


↑ 메이븐 프로젝트


  1. 컴퓨터 프로그램 내에의 연도 표기 중에서 두 자리 숫자인 세기(century)를 생략한 연도 표현으로 인해 2000년에 컴퓨터 운영 체제 및 각종 업무용 응용 프로그램 등에서 2000년을 1900년과 동일하게 「00」년으로 인식함으로써 발생될 수 있는 각종 문제를 말한다. 또한 밀레니엄 버그를 Y2K 문제라고도 하는데, Y는 연도(year)의 첫 글자를 딴 것이고, K는 1000(kilo)에서 딴 것으로 2000년을 의미한다. [본문으로]
반응형

'Java+ > Example' 카테고리의 다른 글

LOGBack Configurator with JMX  (0) 2014.07.20
현지어로 언어명 보여주기  (0) 2014.02.09
JSTL Custom Tag using Spring Beans  (0) 2013.12.01
Spring Message Source from Database  (1) 2013.03.03
Infinite Routing DataSource  (1) 2013.01.13
Mybatis Type Handler  (1) 2012.09.30
Using AUTO_INCREMENT keys  (0) 2011.03.01
//
반응형

Introduce



웹프로젝트 생성 후 추가적으로 해야할 작업을 정리합니다.



프로젝트를 생성하면 아래와 같은 구조로 생성이 됩니다.





Create Resource Folder


기본적인 메이븐 구조에 맞게 있어야 하는 폴더가 안 만들어져 있습니다.


main/java

main/resources <- 이미 생성되어 있음

test/java

test/resources


폴더를 생성하고


main/webapp


폴더는 삭제합니다.



Project Preperties 로 들어갑니다. (프로젝트에서 마우스 오른쪽 버튼 - Properties)


Java Build Path에 3개는 이미 추가되어 있으니(폴더도 없었으면서 -_-)  한개 빠진 폴더를 추가합니다.


Add Folder 버튼 클릭



남은 하나의 폴더(test/resources)를 추가합니다.



OK 후 Java  Resources 쪽에 보면 4개의 폴더가 적용되어 있습니다.





Change JRE System Library


저는 JDK 1.5 가 없습니다. 1.6 을 사용합니다. 하지만 메이븐 프로젝트를 만들면 기본적으로 빌드를 1.5로 하게 되어 있습니다. 이클립스에서 알아서 1.6으로 해주지만 경고가 표시됩니다.



Project Facets 설정 에서 1.6 으로 바꿔줄 수 있지면 나중에 pom.xml 설정을 바꾸다 보면 다시 원상 복귀 됩니다.


해결방법은 pom.xml 에서 플러그인 부분을 아래와 같이 추가 후 저장합니다.


<build>

<finalName>maven.project</finalName>


<!-- 이거 -->

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.1</version>

<configuration>

<source>1.6</source>

<target>1.6</target>

</configuration>

</plugin>

</plugins>

</build>

</project>


그러면 아래와 같이 에러가 나게 됩니다.



하라는대로 합니다. ㅎㅎ 프로젝트 오른쪽 버튼 클릭후 Maven - Update Project.



그럼 메이븐 프로젝트 선택하고 나옵니다. 현재 작업중인 프로젝트를 선택합니다.


그러면 이제 1.6 으로 돌아가게 됩니다. 물론 경고도 사라집니다.




Change Web Resource Location


처음 메이븐 웹 프로젝트를 만들면 웹 관련 폴더는 {프로젝트 루트}/src/main/webapp 에 있습니다.


이게 좀 소스 찾아 들어가려면 귀찮습니다. -_-;; 이 부분을 {프로젝트 루트}/webapp 로 변경하겠습니다.


이미 위에서 src/main/webapp 폴더는 삭제했습니다. 삭제하지 안았다면 삭제합니다.


프로젝트 바로 아래에 webapp, WEB-INF 폴더, web.xml(servlet 2.5) 파일을 생성합니다.



webapp 경로가 바뀌었으니 pom.xml 파일에 maven-war-plugin 설정을 추가합니다.


<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-war-plugin</artifactId>

<version>2.4</version>

<configuration>

<warSourceDirectory>webapp</warSourceDirectory>

</configuration>

</plugin>

</plugins>

</build>

</project>


수정 후 저장을 하면 다시 Update Project 하라고 에러가 납니다.


아직 추가 설정을 더 해줘야합니다!!


Navigator 뷰에서 프로젝트를 본 후 .settings 폴더에서 두개의 파일을 수정합니다.



.jsdtscope - 블럭된 부분을 삭제합니다.


<?xml version="1.0" encoding="UTF-8"?>

<classpath>

<classpathentry kind="src" path="src/main/webapp"/>

<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>

<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">

<attributes>

<attribute name="hide" value="true"/>

</attributes>

</classpathentry>

<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>

<classpathentry kind="output" path=""/>

</classpath>


org.eclipse.wst.common.project.facet.core.xml - jst.web 버전을 2.5로 변경합니다. (자신의 web.xml 따라서 변경)


<?xml version="1.0" encoding="UTF-8"?>

<faceted-project>

  <fixed facet="wst.jsdt.web"/>

  <installed facet="jst.web" version="2.5"/>

  <installed facet="wst.jsdt.web" version="1.0"/>

  <installed facet="java" version="1.6"/>

</faceted-project>


모두 저장 후 Project Explorer 뷰로 이동 후 Maven - Update Project


프로젝트를 보면 Deployment Descriptor 가 표시 되었습니다.



Maven Install 이나 War Export 해보면 정상적인 구조로 말리는 걸 확인할 수 있네요~


반응형
//
반응형

이제서야 OSGi 에 관심이 생겨서 뭔가를 만들어보기 위해서 OSGi + Tomcat 6 + SpringDM[각주:1] 개발 환경을 구성해 봅니다.


Eclipse Indigo + Maven Integration for Eclipse





Create Project


File - New - Other... → Maven - Maven Project




[maven-archetype-quickstart] 선택합니다.



[Group Id], [Artifact Id] 아무거나 입력 합니다. -_-;;


[Package] 는 필요가 없습니다.





Create Target Definition


File - New - Other... → Plug-in Development - Target Definition



[Parent Folder]는 전에 만든 "spring-dm-platform" 프로젝트를 선택합니다.


File name: spring-dm-tomcat.target

Initalize the target definition with: Nothing



lib 폴더를 하나 생성합니다.


target 폴더는 메이븐 라이브러리가 복사되는 곳이고, lib 폴더는 메이븐으로 구하지 못한 라이브러를 넣어둘 것입니다.



spring-dm-tomcat.target 파일을 열어 편집합니다.


Target: SpringDM with Tomcat


오른쪽 Add... 버튼을 클릭해서 Locations 을 추가합니다.



Directory 선택



Variables.. 를 이용해서 현재 프로젝트 경로(project_loc)를 얻어내고 하위 폴더 target 을 입력합니다. (그냥 입력해도 됨..)



같은 방법으로 lib 폴더도 선택합니다.



파일 저장 후 Windows - Preferences - Plug-in Development - Target Platform


SpringDM with Tomcat 을 선택합니다.






Running OSGi Framework


이제 한번 실행시켜 봅시다.


Run - Run Configurations...



왼쪽 메뉴 중에 OSGi Framework 에서 오른쪽 버튼 클릭 - New



이름 적당히 지어 주시고 Run 을 클릭해 봅시다.



org.eclipse.osgi 플러그인이 없다고 에러가 납니다.





Setting Osgi Framework on Maven


이제 메이븐으로 OSGi Framework 라이브러리를 세팅합시다.


pom.xml 파일을 열어 아래와 같이 수정 합니다.



메이븐에 대해서 설명하지는 않겠습니다. -_-;;


위의 라이브러리 저장소(repository)는 SpringSource Repository(FAQ)에서 확인할 수 있습니다.


이제 SpringSource Repository에서 번들(라이브러리)를 하나씩 찾아서 넣어야 합니다. ㅠ_ㅠ;;


검색하는 방법은 [Advanced Search]나 오른쪽 상단 [Quick Search] 을 이용해서 검색하면 됩니다.



일단 OSGi Framework 실행 했을 때 없다고한 플러그인 라이브러리를 검색해봅시다.


검색해서 나온 버전 중 가장 최신 버전을 선택합니다.



중간에 보면 Maven 부분이 있습니다. 이걸 복사해서 <dependencies> </dependencies> 사이에 붙여넣기 하면 됩니다. ㅎㅎ



<dependencies>

<!-- 라이브러리 설정 -->

<dependency>

<groupId>org.eclipse.osgi</groupId>

<artifactId>org.eclipse.osgi</artifactId>

<version>3.7.1.R37x_v20110808-1106</version>

</dependency>

</dependencies>


저장 후 pom.xml 파일에서 오른쪽버튼 클릭 후 Run As - Maven install 클릭 합니다.



그러면 target 폴더에 jar 파일이 복사가 됩니다.



이제 spring-dm-tomcat.target 파일을 열어봅시다.


아래와 같이 번들이 추가 되어있습니다.


※ 메이븐을 이용해서 빠르게 라이브러리를 바꿔치기 하다보면 번들(라이브러리)이 갱신이 안될 때가 있는데 그냥 파일 닫았다가 다시 열어주면 갱신이 되더군요....



맨위의 타이틀 오른쪽에 "Set as Target Platform"을 클릭해야 실제 적용이 됩니다. 주의!



이제 다시 Run Configurations 로 가봅시다. 추가한 번들이 올라와 있습니다. 선택 후 Run!



콘솔 창을 보면 OSGi Framework 가 실행되었습니다. ㅠ_ㅠ



이제 OSGi 할 준비가 된 것입니다. ㅋㅋ


톰켓이나 웹로직 같이 끄려면 빨간 버튼(Terminate)을 이용해서 끄면 됩니다.


나중에 톰켓를 띄우게 될텐데 OSGi Framework 한번 실행한 상태에서 한번 실행하면 톰켓 포트 충돌로 인한 에러를 볼 수 있습니다.




Setting SpringDM on Maven


바로 SpringDM을 적용해 봅시다!!


SpringSource Repository 에서 "spring", "spring-osgi", "slf4j" 를 검색해서 최신 버전을 적용 합니다.



이제 pom.xml 에서 마우스 오른쪽 버튼 - Run As - Maven install 해서 jar 파일을 target 에 생기게 합니다.


그리고 spring-dm-tomcat.target 파일을 열어서 ${project_loc}/target 폴더에 플러그인 갯수가 늘어났는지 확인합니다.


만약 파일은 존재하는데 변경이 되지 안았다면 spring-dm-tomcat.target 파일 닫고 바로 다시 열어주면 카운트가 변경 되어 있을 겁니다.



상단 오른쪽의 "Set as Target Platform" 링크를 클릭하여 라이브러리를 적용시켜 줍니다.



Run Configurations 창으로 가서 추가된 번들(또는 라이브러리)를 선택합니다.


그 후 오른쪽 아래 "Validate Bundles" 버튼을 클릭합니다. 버튼명 그대로 번들들의 유효성을 검사하게 됩니다.



아래와 같이 어떤 라이브러리에서 필요한 라이브러리가 빠져있는지 나옵니다.



웹에 관련된 부분은 바로 이어서 할 것이므로 일단 이 번들은 빼고 구동(Run)합니다.



아래와 같이 나오면 성공! 웹쪽을 뺀 SpringDM 까지 올라갔습니다.


osgi> log4j:WARN No appenders could be found for logger (org.springframework.osgi.extender.internal.activator.ContextLoaderListener).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


osgi> ss


Framework is launched.


id State       Bundle

0 ACTIVE      org.eclipse.osgi_3.7.1.R37x_v20110808-1106

1 ACTIVE      org.springframework.transaction_3.2.1.RELEASE

2 ACTIVE      org.springframework.osgi.core_1.2.1

3 ACTIVE      org.springframework.osgi.extensions.annotations_1.2.1

4 ACTIVE      com.springsource.org.apache.log4j_1.2.16

5 ACTIVE      org.springframework.jdbc_3.2.1.RELEASE

6 ACTIVE      org.springframework.oxm_3.2.1.RELEASE

7 ACTIVE      org.springframework.aspects_3.2.1.RELEASE

8 ACTIVE      com.springsource.org.apache.commons.logging_1.1.1

9 ACTIVE      org.springframework.context.support_3.2.1.RELEASE

10 ACTIVE      org.springframework.core_3.2.1.RELEASE

11 ACTIVE      org.springframework.beans_3.2.1.RELEASE

12 ACTIVE      org.springframework.context_3.2.1.RELEASE

13 ACTIVE      org.springframework.aop_3.2.1.RELEASE

14 RESOLVED    com.springsource.slf4j.log4j_1.6.1

           Master=17

15 ACTIVE      org.springframework.expression_3.2.1.RELEASE

16 ACTIVE      org.springframework.orm_3.2.1.RELEASE

17 ACTIVE      com.springsource.slf4j.api_1.6.1

           Fragments=14

18 ACTIVE      com.springsource.org.aopalliance_1.0.0

19 ACTIVE      org.springframework.osgi.extender_1.2.1

20 ACTIVE      org.springframework.osgi.io_1.2.1


osgi> 




Configuration Log4j


OSGi Framework 를 실행 하면 아래와 같은 경고가 나오게 되는데 흔하디 흔한 log4j.properties / log4j.xml 파일 못 찾는 경고입니다.


log4j:WARN No appenders could be found for logger (org.springframework.osgi.extender.internal.activator.ContextLoaderListener).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


log4j.xml


첨부한 log4j.xml 파일을 프로젝트 폴더에 복사합니다.



Run Configurations 창의 Arguments 탭으로 이동합니다.


VM arguments 부분에 -Dlog4j.debug=true -Dlog4j.configuration=file:log4j.xml 를 추가합니다.


Working directory 부분은 현재 자기의 프로젝트 경로로 바꿔줍니다.



Workspace... 버튼 클릭 후 spring-dm-platform 프로젝트 폴더를 선택하면 됩니다.



이제 OSGi Framework 를 실행하면 로그가 출력 됩니다.


osgi> log4j: Using URL [file:log4j.xml] for automatic log4j configuration.

log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator

log4j: System property is :null

log4j: Standard DocumentBuilderFactory search succeded.

log4j: DocumentBuilderFactory is: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

log4j: debug attribute= "null".

log4j: Ignoring debug attribute.

log4j: reset attribute= "false".

log4j: Threshold ="null".

log4j: Retreiving an instance of org.apache.log4j.Logger.

log4j: Setting [org.springframework.osgi.web.tomcat.internal] additivity to [false].

log4j: Level value for org.springframework.osgi.web.tomcat.internal is  [debug].

log4j: org.springframework.osgi.web.tomcat.internal level set to DEBUG

log4j: Class name: [org.apache.log4j.ConsoleAppender]

log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"

log4j: Setting property [conversionPattern] to [%d _ %t _ %p _ %c _ %m%n].

log4j: Adding appender named [console] to category [org.springframework.osgi.web.tomcat.internal].

log4j: Retreiving an instance of org.apache.log4j.Logger.

log4j: Setting [org.springframework] additivity to [false].

log4j: Level value for org.springframework is  [info].

log4j: org.springframework level set to INFO

log4j: Adding appender named [console] to category [org.springframework].

log4j: Level value for root is  [warn].

log4j: root level set to WARN

log4j: Adding appender named [console] to category [root].

2013-03-27 00:54:43,505 _ Start Level Event Dispatcher _ INFO

_ org.springframework.osgi.extender.internal.activator.ContextLoaderListener

_ Starting [org.springframework.osgi.extender] bundle v.[1.2.1]

2013-03-27 00:54:43,545 _ Start Level Event Dispatcher _ INFO

_ org.springframework.osgi.extender.internal.support.ExtenderConfiguration

_ No custom extender configuration detected; using defaults...

2013-03-27 00:54:43,550 _ Start Level Event Dispatcher _ INFO

_ org.springframework.scheduling.timer.TimerTaskExecutor _ Initializing Timer


osgi> 


여기까지 했으면 이제 웹을 제외한 SpringDM을 사용할 준비가 되었습니다.




Setting Web Platform


이제 거의 다 왔습니다.... 후우~.. 이제 웹도 되게 합시다!



Run Configurations 창에서 전 단계에서 선택하지 않았던 4개의 웹 관련 번들을 선택 후 검사합니다. (Validate Bundles 버튼)



아래에 나온 없는 패키지가 포함된 번들을 찾아줘야 합니다.



일단 서블릿 2.4 버전을 찾아서 넣어줍시다.



이렇게 추가된 라이브러리를 적용한 후 다시 Run Configurations 창을 엽니다.


Add Required Bundles 버튼을 클릭하면 필요한 라이브러리를 자동으로 선택 해줍니다. (만약 있다면..)



이제 번들 유효성 검사를 해보면 아무 이상이 없다고 합니다.



실행! 잘 되는듯 하다가 에러가 나는군요...


2013-03-28 23:20:49,878 _ WebExtender-Init _ INFO

_ org.springframework.osgi.web.extender.internal.activator.WarListenerConfiguration

_ No custom extender configuration detected; using defaults...

Exception in thread "WebExtender-Init" java.lang.NoClassDefFoundError: org/apache/catalina/Loader

at o.s.osgi.web.extender.internal.activator.WarListenerConfiguration.createDefaultWarDeployer(WarListenerConfiguration.java:194)

at org.springframework.osgi.web.extender.internal.activator.WarListenerConfiguration.<init>(WarListenerConfiguration.java:105)

at org.springframework.osgi.web.extender.internal.activator.WarLoaderListener$1.run(WarLoaderListener.java:361)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.ClassNotFoundException: org.apache.catalina.Loader

at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)

at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)

at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)

at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 4 more


톰켓 번들을 설치합시다.


내용이 너무 길어저 pom.xml 만 남깁니다.



번들(라이브러리) 적용 후 우효성 검사를 하면 이상이 없다고 합니다.


보면 서블릿 번들이이 2.4/2.5 두개가 있는데 이중에 한가지만 선택하면 되겠습니다.



이제 실행해 봅시다.


WebExtender-Init _ ERROR _ o.s.osgi.web.deployer.tomcat.TomcatWarDeployer _ No Catalina Service found, bailing out

o.s.osgi.service.ServiceUnavailableException: service matching filter=[(objectClass=org.apache.catalina.Service)] unavailable


WebExtender-Init _ ERROR _ o.s.osgi.web.extender.internal.activator.WarLoaderListener _ Cannot property start Spring DM WebExtender; stopping bundle...

o.s.osgi.OsgiException: Cannot create Tomcat deployer

Caused by: o.s.osgi.service.ServiceUnavailableException: service matching filter=[(objectClass=org.apache.catalina.Service)] unavailable


WebExtender-Init _ INFO _ org.springframework.scheduling.timer.TimerTaskExecutor _ Cancelling Timer


org.apache.catalina.Service 서비스를 찾을 수 없다. 즉 톰켓이 안 떠있다는 겁니다.


catalina.start.osgi-6.0.16-20080327.121306-4.jar


첨부한 번들을 lib 폴더에 복사해주고 적용 시킵니다. (이건 메이븐에 없더군요...)



마지막으로 실행!


Tomcat Catalina Start Thread _ INFO _ o.s.osgi.web.tomcat.internal.Activator _ Starting Apache Tomcat/6.0.32 ...

Tomcat Catalina Start Thread _ DEBUG _ o.s.osgi.web.tomcat.internal.Activator _ Reading default server configuration from  bundleresource://45.fwk1110027070/conf/embedded-server-defaults.properties

2013. 3. 28 오후 11:40:53 org.apache.catalina.startup.Embedded start

정보: Starting tomcat server

2013. 3. 28 오후 11:40:53 org.apache.catalina.core.StandardEngine start

정보: Starting Servlet Engine: Apache Tomcat/6.0.32

2013. 3. 28 오후 11:40:53 org.apache.coyote.http11.Http11Protocol init

정보: Initializing Coyote HTTP/1.1 on http-127.0.0.1-8080

2013. 3. 28 오후 11:40:53 org.apache.coyote.http11.Http11Protocol start

정보: Starting Coyote HTTP/1.1 on http-127.0.0.1-8080

Tomcat Catalina Start Thread _ INFO _ o.s.osgi.web.tomcat.internal.Activator _ Succesfully started Apache Tomcat/6.0.32

WebExtender-Init _ INFO _ o.s.osgi.service.importer.support.OsgiServiceProxyFactoryBean _ Found mandatory OSGi service for bean []

Tomcat Catalina Start Thread _ INFO _ o.s.osgi.web.tomcat.internal.Activator _ Published Apache Tomcat/6.0.32 as an OSGi service

WebExtender-Init _ INFO _ o.s.osgi.web.deployer.tomcat.TomcatWarDeployer _ Found service Catalina


후우... 성공!


web.xml


마지막으로 첨부한 web.xml 파일을 conf/web.xml 에 복사합니다. (그냥 톰켓에 있는 web.xml 입니다)



이 파일이 있어야 나중에 웹어플 배치했을 때 정상적으로 됩니다.


안그러면 배치했을 때 아래 로그와 함께 영원히 404를 볼 수 있습니다.


[ INFO - WebExtender-Init] org.springframework.osgi.web.extender.internal.activator.WarLoaderListener - hello.web (hello.web) is a WAR, scheduling war deployment on context path [/hello.web] (web.xml found at [bundleentry://11.fwk854535264/WEB-INF/web.xml])

2013. 3. 30 오전 2:03:35 org.apache.catalina.startup.ContextConfig defaultWebConfig

정보: No default web.xml

[ INFO - Timer-0] org.springframework.osgi.web.deployer.tomcat.TomcatWarDeployer - Successfully deployed bundle [hello.web (hello.web)] at [/hello.web] on server org.apache.catalina.startup.Embedded/1.0




Trouble Shooting


설정을 바꿨는데도 안바뀐다면?


Run Configurations 의 Settings 탭에서 "Clear the configuration area before launching"를 체크해주세요.



중간 중간 아래와 같은 에러가 난다면? 하라는 대로 하면 됩니다. -_-;;





마지막으로 최종 pom.xml 파일 첨부합니다.


pom.xml



  1. 구) Spring OSGi / 신) Spring Dynamic Modules [본문으로]
반응형

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

SpringDM Test Project - hello.osgi  (0) 2013.04.07
//

Maven Repository for Oracle Library

Posted at 2012. 12. 18. 20:43 | Posted in Java+
반응형

메이븐 pom.xml 에서 오라클 라이브러리를 사용하기 위한 설정입니다.


메이븐 구조의 프로젝트에서 오라클 라이브러를 쉽게 사용하기 위해서 이것저것 찾아보다가 현재 아래의 저장소 URL 이 제일 적당한 것 같습니다.


<project ...>

...


<repositories>

<repository>

<id>codelds</id>

<url>https://code.lds.org/nexus/content/groups/main-repo</url>

</repository>

</repositories>


<dependencies>

...

<!-- oracle -->

<dependency>

<groupId>com.oracle</groupId>

<artifactId>ojdbc6</artifactId>

<version>11.2.0.3</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>com.oracle</groupId>

<artifactId>ucp</artifactId>

<version>11.2.0.3</version>

<scope>compile</scope>

</dependency>

</dependencies>


</project>



각 버전을 확인 하는 방법은 브라우저에서 위 저장소 URL 을 입력하면 [groupId / artifactId / version] 순으로 디렉토리 구조로 되어 있습니다.


목록을 보면 오라클 이외에도 많은 라이브러리가 있는 것을 볼 수 있습니다.


자기가 필요로하는 라이브러리를 찾아봅시다 -_-;;


ojdbc6.jar 를 찾아보면 아래와 같은 구조로 되어 있습니다.



딱 보면 감이 오시겠지면


1 = groupId

2 = artifactId

3 = version


반응형

'Java+' 카테고리의 다른 글

Find class in jar files  (0) 2018.02.19
web.xml 서블릿 버전별 DTD  (1) 2013.03.03
<jsp:forward page="url" /><jsp:include /> <%@ include %>  (0) 2010.04.25
TortoiseSVN 사용하기  (2) 2009.11.16
썸네일(Thumbnail) 만들기  (1) 2009.08.09
Java2Html  (0) 2009.07.19
Jad + JadClipse  (6) 2009.07.11
Java with SQLite  (1) 2009.06.29
Java Database Connectivity  (0) 2009.02.25
//

Maven Integration for Eclipse

Posted at 2012. 2. 20. 03:30 | Posted in Tools/Eclipse
반응형
메이븐을 이용해서 웹프로젝트는 사용할 수 있도록 해보겠습니다.

아직까지도 불편하기만 하지만.. 쩝..

http://eclipse.org/m2e/



Eclipse Indigo(3.7)와 JDK 1.6 으로 설치 해보겠습니다.


아래 두개의 사이트에서 업데이르를 받습니다.

Maven Integration for Eclipse Update Site : http://m2eclipse.sonatype.org/sites/m2e/

Maven Integration for Eclipse Extras Update Site : http://m2eclipse.sonatype.org/sites/m2e-extras/



Maven Intergration for Eclipse WTP 플러그인이 웹 어플을 만들 수 있게 해주는 플러그인 입니다.



플러그인이 둘 다 설치되면 이클립스를 재시작 합니다.

이제 이클립스에서 메이븐 프로젝트를 생성할 수 있습니다.




위와 같은 경고 메세지가 보이면 eclipse.ini 파일에 jdk 위치를 직접 지정합니다.

(경로는 각자 다르니 알아서.. -_-+)

  1. -startup
  2. plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
  3. --launcher.library
  4. plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
  5. -product
  6. org.eclipse.epp.package.jee.product
  7. -vm
  8. C:\Program Files\Java\jdk1.6.0_27\bin\javaw.exe
  9. --launcher.defaultAction
  10. openFile
  11. --launcher.XXMaxPermSize
  12. 256M
  13. -showsplash
  14. org.eclipse.platform
  15. --launcher.XXMaxPermSize
  16. 256m
  17. --launcher.defaultAction
  18. openFile
  19. -vmargs
  20. -Dosgi.requiredJavaVersion=1.5
  21. -Xms40m
  22. -Xmx512m


이제 웹프로젝트를 만들어서 테스트 해봅시다~

File - New - Other... (Ctrl + N)

Maven Porject 를 선택합니다.


그냥 Next 클릭.



"maven-archetype-webapp" Archetype 을 선택합니다.



Group Id 와 Artifact Id(프로젝트명)를  적습니다.



아래와 같이 프로젝트가 만들어졌습니다.



평소 이클립스에서 하듯이 서버에 배치하고 실행해보면 페이지가 나오는 것을 확인할 수 있습니다.




JDK 버전 맞추기

그나마 우리가 쓰던대로 하려면 아주 조금 더 설정을 해줘야합니다. -_-;;;

만약 JDK 1.6 이상을 쓴다면 아래와 같이 경고가 나는 것을 확인할 수 있습니다.

Description Resource Path Location Type
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.  first-maven  Build path JRE System Library Problem


메이븐 프로젝트는 기본적으로 Java 1.5를 사용하게 설정되어 있네요.

프로젝트에서 마우스 오른쪽 버튼 클릭 - Properties (Alt + Enter) 선택해서 프로젝트 설정으로 들어갑니다.

Java 를 1.6 으로 변경합니다.





Project Explorer 정렬 문제

프로젝트 생성 후에 작업을 하다보면 웹 파일쪽의 뭔가 이상합니다. -_-;;

폴더 a-z , 파일 a-z 였던 정렬이 뒤엉켜 버립니다. ㅠ_ㅠ


그나마 쓸 수 있는 방법은 아래와 같습니다.

Project Explorer 오른쪽의 View Menu(아래쪽 세모)를 클릭 - Customize View 선택.


JavaScript Elements, Web Resources, Resources 를 체크 해제합니다.


이제는 제대로 보이네요 ㅎㅎ




Java Resource 설정

이제 자바 파일을 생성해 보겠습니다.

근데 이상하게 나옵니다 -_-;; 그냥 파일로 인식이 되네요...


수정해봅시다. ㅠㅠ

프로젝트 설정으로 갑니다.

Java Build Path 부분에서 Source 탭으로 이동합니다.

기존에 있던 폴더를 삭제 후 다시 폴더를 추가합니다.


src/main/reources 를 선택합니다.



OK 버튼을 클릭합니다.


이제야 제대로 보이네요 ㅎㅎㅎ




메이븐을 사용하는 가장 큰 이유인 pom.xml 을 이용한 라이브러리 자동 세팅(?)을 이용하기 m2eclipse 플러그인을 설치했습니다.

한발치 떨어져서 보면 열라 좋아 보이지만 막상 쓸려고하니까 기존 Dynamic Web Project 에 익숙해져서 인지 불편하네요..

그나마 두번째 플러그인(WTP를 위한 플러그인)이 없었을 때는 더 불편했었죠... ㅠㅠ

설치 후에 버그(?)들 쉽게 해결할 수 있는 방법 아시는분~

반응형

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

Eclipse JVM 경로 지정하기  (0) 2016.09.13
Eclipse + SVN Plugin  (1) 2012.03.29
Eclipse + TPTP Remote  (1) 2012.01.20
Eclipse + TPTP (Eclipse Test & Performance Tools Platform)  (4) 2012.01.01
Eclipse + MyBatis Generator  (1) 2011.07.04
installation Oracle Enterprise Pack for Eclipse  (2) 2011.05.22
Eclipse + STS (SpringSource Tool Suite)  (1) 2011.01.16
Eclipse Plugins for JBoss technology  (1) 2011.01.11
Properties Editor  (1) 2009.11.17
UTF-8 설정  (0) 2009.11.16
//