Posts Tagged ‘Eclipse’
maven – Eclipse에서 maven project + WTP 사용하기
바로 이전 포스트에서는 command에서 maven project를 만들고, 그것을 eclipse에서 사용할 수 있도록
바꾸고 곧바로 WTP에서 인식할 수 있도록 하는 방법에 대해 소개했다.
이번에는 직접 eclipse에서 프로젝트를 생성하고, WTP에서 사용할 수 있는 방법에 대해 써보고자 한다.
1. maven 프로젝트 생성
File > New > Other > Maven > Maven Project를 선택한다.
archetype은 webapp로 지정한다.
2. 프로젝트 파일 세부 설정하기
프로젝트를 생성하면, 위와 같은 구조로 생성이 된다. 언제나 그랬듯이, 디렉토리 구조를 변경하고 싶다. junit은 3.8.1로 되어 있어서, 버전도 바꾸고 싶고. 이 작업을 해보자.
프로젝트의 properties를 바꿔보자. (프로젝트 view에서 context 메뉴 띄우고, properties)
Project Facets를 선택하자.
우측의 Convert to faceted form..을 선택하자.
그러면, 다음의 화면이 뜬다.
JavaScript를 선택하고, Dynamic Web Module을 선택한다.
Dynamic Web Module의 버전을 고르자. Tomcat 7의 경우, 3.0으로 해도 되나, Tomcat 6이라면 2.5로 하자.
하단의 Further configuration available..을 클릭한다.
Context root에 웹 애플리케이션에서 사용할 context root를 입력한다.
Content directory에 web content를 저장할 디렉토리를 입력한다. eclipse에서의 디폴트 값은 WebContent이고, 커맨드에서 maven 프로젝트를 생성하면 webapp로 지정될 것이다.
3. 디렉토리/ pom.xml 변경하기
사용할 junit의 버전을 3.8.1에서 4.8.2로 변경하고, webapp의 위치를 pom.xml에 반영하자.
4.0.0 com.luran secondweb war 0.0.1-SNAPSHOT secondweb Maven Webapp http://maven.apache.org junit junit 4.8.2 test secondweb maven-war-plugin webapp
Java Resources 탭에서 context 메뉴를 띄워서 Source Folder를 생성하자. (src/java, src/java/resources, src/test, src/test/resources)
디폴트로 생성된 src/main/* 등은 삭제하자.
생성된 디렉토리의 구조는 다음과 같다.
4. WTP에 연동하기
Servers 탭에 지금 생성한 secondweb 프로젝트를 추가한다. (Add and remove)
이제 웹 애플리케이션을 시작시켜서 테스트할 수 있다.
http://localhost:8080/secondweb으로 접속하면, 위와 같은 화면을 볼 수 있다.
maven – maven project를 eclipse + WTP에서 사용가능하게 바꾸기
eclipse에서 web project를 작성하게 되면 사용하게 되는 것이 WTP이다.
그러나, 앞서 maven 프로젝트를 생성한 것만으로는 자동으로 WTP와 연동이 되지 않는다.
이를 위해 설정을 바꿔보자.
1. 테스트 프로젝트 만들기
interactive 모드로 프로젝트를 생성한다.
mvn archetype:generate -DarchetypeCatalog=internal
목록에서 “19: internal -> org.apache.maven.archetypes:maven-archetype-webapp”. 19번 선택.
groupId : com.luran 입력
artifactId : firstweb
1.0-SNAPTSHOT : 엔터
package : 엔터
2. pom.xml 바꾸기, 디렉토리 구조 바꾸기
4.0.0 com.luran firstweb war 1.0-SNAPSHOT firstweb Maven Webapp http://maven.apache.org junit junit 4.8.2 test firstweb src/java src/test target/classes target/test-classes src/java/resources src/test/resources maven-war-plugin webapp
디렉토리 구조를 위의 pom.xml에 맞춰 바꾸자.
변경 전의 디렉토리 구조는 다음과 같다.
pom.xml에 표기한 대로 바꾼 후의 디렉토리 구조는 다음과 같다.
바꾼 후에, mvn package를 실행하면 다음과 같이 다른 디렉토리가 생성되는 것을 확인할 수 있다.
3. Eclipse화시키기
현재 파일 상태를 eclipse에서 사용하기 편하게 mvn에서 기능을 제공한다.
pom.xml이 있는 곳에서 mvn eclipse:eclipse라고 하면 pom.xml을 기반으로 eclipse 설정을 만들어 줄 것이다.
변경 전은 다음과 같다.
pom.xml이 있는 곳에서,
mvn eclipse:clean eclipse:eclipse
를 실행하면 다음과 같이 .classpath, .project, .settings가 생성되는 것을 확인할 수 있다.
이제 제대로 인식되는지 eclipse에서 읽어들여보자.
4. WTP에서 인식되게 하기
WTP에서 사용할 수 있도록 하기 위해, pom.xml에 다음의 설정을 추가한다.
maven-eclipse-plugin 2.8 2.0 /
그리고, 다시 mvn eclipse:clean eclipse:eclipse 를 실행하자.
기존 프로젝트 파일을 import 시켜보자.
5. WTP용 WAS Server 등록
File > New > Other > Server > Server 를 선택한다.
그러면, 사용할 서버의 종류를 선택할 수 있다.
6. WTP 서버에 연동하기
서버를 생성한 직후 또는 별도 생성 후, Java EE 뷰의 Servers 탭에서 웹서버에 firstweb 을 추가할 수 있다.
Add and remove를 선택하면 창이 뜨고, 이 창에서 해당 웹 애플리케이션을 추가하자.
그러면, 위와 같이 해당 항목에서 context 메뉴를 띄워서 웹 애플리케이션을 시작/ 중지시킬 수 있게 된다.
web.xml 등의 별도 설정을 하지 않은 상태에서의 테스트는 다음과 같다.
maven – eclipse indigo + m2eclipse
2011/6/22에 릴리즈된 Eclipse Indigo의 기능중,
* m2eclipse에 대한 지원이 강화되었다는 것
* myln을 통해 Hudson을 연동할 수 있다는 것
등의 이유로, Helios에서 Indigo로 업그레이드 해보려고 한다. (그냥 다시 설치)
1. m2e plugin 설치
최신 m2eclipse 플러그인 이름이 m2e로 변경되었다.
Help > Install New Software 에서 m2e를 찾아보자.
Collaboration 밑에 m2e 항목을 발견할 수 있다.
체크를 하고 설치하자.
“Finish”를 하면, 프로젝트가 생성된다.
생성된 디렉토리 구조는 다음과 같다.
생성된 pom.xml은 아래와 같다.
기존의 WTP 프로젝트는 등록한 WAS에 곧바로 연결하여 사용할 수 있는데, 현재 maven으로 만든 프로젝트는 WAS에 곧바로 사용할 수가 없다. (불편하다!)
일단, 이렇게 생성한 프로젝트가 정상적으로 실행되는지부터 살펴보고 나중에 환경 설정을 바꿔보자.
mvn package를 실행하면, target 디렉토리내 myweb.war이 생성된다.
$CATALINA_HOME/webapps에 myweb.war를 복사하고,
웹 브라우저에서 http://localhost:8080/myweb을 실행하면,
과 같이, Hello World!가 출력된다.
그러나, 매번 이렇게 war 파일을 복사하는 건 너무 불편하다. 분명 더 쉽게 쓰는 방법이 있을 것이다.
[eclipse plug-in] moreunit – 테스트 유닛은 어디에?
moreunit은 작성중인 클래스에 테스트 코드가 작성되어 있는지를 시각적으로 보여주는 플러그인이다.
해당 플러그인에 대한 자세한 설명은
http://moreunit.sourceforge.net/index.html
에서 확인할 수 있다.
설치는, 직접 다운로드하여 플러그인 디렉토리에 풀어주거나,
이클립스 플러그인 설치 메뉴로부터,
http://moreunit.sourceforge.net/update-site/
를 등록하여 다른 플러그인 설치 과정과 동일하게 설치하면 된다.
본인의 경우, 별다른 기본 설정없이도 작성중인 클래스에 대해 테스트 클래스를 찾아 보여주었는데,
설정이 동작하지 않는다면 properties context menu로부터 세부 설정이 가능하다.
동작시의 화면은 moreunit의 공식사이트에 있는 것과 별 차이가 없다.
직접 테스트해본 화면은 다음과 같다.
우선, 아래 그림은 moreunit을 설치하기 전의 파일 구성이다.
이제 설치를 완료하고 나면, 똑같은 파일리스트에 빨간 동그라미를 표시한 것과 같이 오른쪽 상단에
녹색마크가 표시된다. 이는 해당 클래스에 테스트케이스가 작성되어 있음을 나타낸다.
표시가 생긴 임의의 클래스를 살펴보면, 테스트 케이스가 작성된 메소드에는 메소드의 좌측 라인에 마찬가지로
테스트케이스가 있음을 나타내는 마크가 보인다.
해당 라인에서 마우스 오른쪽 버튼을 클릭하여 context메뉴를 통해 이동하거나, 단축키 ctrl + j를 누른다면,
해당 메소드의 테스트케이스로 직접 이동할 수 있다.
Eclipse의 내장 hashCode()+equals() VS. Apache의 HashCodeBuilder+EqualsBuilder
Eclipse에 내장된 기능으로도 특정 객체의 hashCode()와 equals()를 작성할 수 있다.
사용법은,
마우스 오른쪽 클릭하여 나오는 context 메뉴로부터 Source > Generate hashCode() and equals() … 를 클릭하면 된다.
그러면, 다음과 같은 코드가 생성될 것이다.
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((link == null) ? 0 : link.hashCode()); result = prime * result + ((menuCode == null) ? 0 : menuCode.hashCode()); result = prime * result + ((menuName == null) ? 0 : menuName.hashCode()); result = prime * result + ((upperCode == null) ? 0 : upperCode.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MenuItem other = (MenuItem) obj; if (link == null) { if (other.link != null) return false; } else if (!link.equals(other.link)) return false; if (menuCode == null) { if (other.menuCode != null) return false; } else if (!menuCode.equals(other.menuCode)) return false; if (menuName == null) { if (other.menuName != null) return false; } else if (!menuName.equals(other.menuName)) return false; if (upperCode == null) { if (other.upperCode != null) return false; } else if (!upperCode.equals(other.upperCode)) return false; return true; }
그런데, Apache의 라이브러리를 사용하면, 보다 깔끔한(!) 코드와 가독성을 얻을 수 있다.
우선, common-lang*.jar를 구하고, 다음과 같이 작성한다.
import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; ... @Override public int hashCode() { return new HashCodeBuilder(3, 11) .append(upperCode) .append(menuCode) .append(menuName) .append(link) .toHashCode(); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MenuItem other = (MenuItem) obj; return new EqualsBuilder() .append(this.upperCode, other.upperCode) .append(this.menuCode, other.menuCode) .append(this.menuName, other.menuName) .append(this.link, other.link) .isEquals(); }
Eclipse에서 java 소스로부터 클래스 다이어그램을 쉽게 만들자/ eUML2
eUML2라는 eclipse 플러그인을 설치하여,
기존에 작성했던 java project의 클래스 다이어그램 및 클래스 연관 관계를 쉽게 그려서 볼 수 있다.
라이센스는 ‘free’ 버전과 ‘studio’ 버전이 있으므로, free를 골라서 설치하자.
eclipse에서 자신의 eclipse 버전에 맞는 것으로 골라서, download 받고 설치하면 된다.
대략 다음의 장점이 있다고 광고하고 있다.
- Real-time code/model synchronization
- UML2.1 compliant and support of OMG XMI
- Advanced reversed engineering
- Powerful true dependency analyze tools
- JDK 1.4 and 1.5 support
- Customizable template support. More…
Eclipse에서 javadoc을 pdf로 출력하기
LaTex를 쓰는 방법은 LaTex의 특성상 가독성이 좋은 결과물을 만들 것으로 기대되나,
별도로 변환을 한번 더 해줘야 하는 번거로움이 있으므로 이왕이면 손이 덜 가는 방법을 찾아보게 되었다.
www.doclet.com에 소개된 library 중 하나인,
AurigaDoclet(http://aurigadoclet.sourceforge.net/)을 사용해 보자.
사용법은 간단하다.
ANT에서 지정할 수 있는 설정은,
<javadoc packagenames=”package-names”
sourcepath=”source-path”
doclet=”com.aurigalogic.doclet.core.Doclet”
docletpath=”aurigadoclet-path”
additionalparam=”options”
>
<classpath refid=”aurigadoclet.class.path” />
</javadoc>
package-names package names source-path path of the java source files aurigadoclet-path path to the AurigaDoclet.jar file in AurigaDoclet’s bin directory options AurigaDoclet options.
이며, 이 때 사용할 수 있는 옵션으로
-format
- The output format.
Supported values: fo,pdf,ps,pcl,svg.
- -out
- Output file path.
- -notoc
- Do not generate TOC page.
- -nonavigation
- Do not generate navigation tree.
- -nolinks
- Do not use hyperlinks.
- -noindex
- Do not generate a keyword index.
- -leftmargin
- Left margin in points. Default is 30.
- -rightmargin
- Right margin in points. Default is 30.
- -topmargin
- Top margin in points. Default is 10.
- -bottommargin
- Bottom margin in points. Default is 10.
- -headertext
- XHTML text to be used as page header.
- -headerfile
- XHTML file to be used as page header.
- -footertext
- XHTML text to be used as page footer.
- -footerfile
- XHTML file to be used as page footer.
- -headerheight
- Height of page headers in points. Default is 50.
- -footerheight
- Height of page footer in points. Default is 20.
- -coverfile
- XHTML file to be used a cover page.
- -cssfile
- CSS file to used for formatting the output.
Default css file is located in src/com/aurigalogic/doclet/resources/default.css
- -xslfile
- Custom xsl file to be used for formatting the output.
가 있다.
따라서, Eclipse에서 이 정보를 활용하여, aurigadoclet을 사용하도록 환경설정하고
실행시 옵션으로 위의 옵션을 택하여 지정하면 된다.
1. Eclipse의 해당 프로젝트로부터, Export > JavaDoc > Use custom doclet 선택
2. Docletname에 com.aurigalogic.doclet.core.Doclet 을
3. Doclet class path에 설치한디렉토리binAurigaDoclet.jar 를 써준다.
Next를 누른다.
4. Extra Javadoc options에
-format pdf -out “만들 pdf의 경로와 이름” 을 적어주고,
Finish 누르면 pdf가 생성된다.