2018년 3월 11일 일요일

maven 2 기본

maven 2 기본(1)
1. maven ?

maven 은 Apache 에서 공개 프로젝트로 진행중인 프로젝트 관리툴이며, java 기반의 모든 프로젝트를 통합 관리한다. maven 은 프로젝트 빌드에 가장 좋은 모델을 제공하여 생산성 향상에 도움이 된다.
maven 은 많은 플러그인 들로 구성되며, 이 플러그인 들을 통해서 Builds, Documentation, Reporting, Dependencies, SCMs, Releases, Distribution 등이 주요한 feature 로 제공된다.
각각의 플러그인 들을 goal 이라고 불리우는 서비스를 제공하며, 각각의 goal 은 필요에 따라서 parameter 를 요구하기도 한다.
현재 version 2.x 가 개발/사용 중이다.

2. maven 호출/실행 형태

mvn [plugin]:[goal] [parameters]

위와 같이 명령을 실행하면 Maven은 해당 플러그인이 로컬 저장소에 있는지 확인하고 없으면 다음의 위치에서 다운로드 받는다. (from http://repo1.maven.org/maven2/ , specifically the org/apache/maven/plugins subfolder)
플러그인 준비가 완료되면 주어진 파라메터를 사용해서 지정된 goal을 실행한다.
제공되는 플러그인의 종류와 각각의 goal 은 http://maven.apache.org/plugins/index.html 에 상세히 기술되어 있다.

mvn [task]

task 로 정의된 일들을 실행한다.
task 는 plug-in 의 goal 들의 조합이다.
다음과 같은 task 등이 사용된다.

complie : src/main/java 디렉토리에 위치한 구현 코드만 컴파일
test-compile : src/main/test 디렉토리에 위치한 테스트 코드를 컴파일 한다. test-compile 을 실행할 경우 compile 이 먼저 실행된다
package : compile, test-compile, test, package 순으로 task 가 실행된 후 jar, war 파일 등으로 packaging 이 target 디렉토리 하위에 생성된다. 생성되는 jar, war의 명명 규칙은 artifactId-version.packaging이 된다.
install : install 은 package 에 의하여 생성된 jar, war 파일을 Local Repository에 등록한다.
deploy : deploy 는 jar, war 파일을 외부 Remote Repository에 등록한다.
site : 문서화 작업을 수행한다.


3. 프로젝트 생성시 용어

* groupId
Maven은 프로젝트를 구분하기 위해 groupId와 artifactId를 사용합니다.
groupId 는 인터넷에서 내 프로젝트를 구분하기 위해서 사용되는 것으로 java package name 형태로 만든다.
(Maven naming 참조: http://maven.apache.org/guides/mini/guide-naming-conventions.html)
ex) org.apache.maven, org.apache.jakarta.commons

* artifactId
artifact 는 프로젝트의 결과물을 의미하며 버전이 없는 jar 파일 이름으로 lowercase 문자로 설정한다.
third-party jar 를 생성해야 하는 경우라면, 기존 배포되는 이름을 artifactId 로 설정한다.
ex) maven, commons-math

* version
버전을 지정한다. (특히 artifact 를 distribute 할때)
숫자와 . 을 사용해서 표기하며 날짜를 버전에 표기하지는 않을것을 권고함.
third-party jar 를 생성하는 경우, 그들의 버전 정책을 따른다.
eg. 2.0 , 2.0.1 , 1.3.1



출처: http://lefthand.tistory.com/5 [lefthand's note]

Maven 2.0.9 설치
1. 다운로드
maven.apache.org 에서 최신 버전 다운로드
ex) http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.0.9-bin.zip

2. 압축풀어 적당한 위치에 복사
C:\Program Files\Apache Software Foundation\\apache-maven-2.0.9

3. 환경변수 등록
    3-1. Maven 관련 환경변수
          M2_HOME(mandatory)
             ex) "C:\Program Files\Apache Software Foundation\apache-maven-2.0.9"
                  (맨끝의 \ 는 포함시키지 않는다.)
          M2(mandatory) "%M2_HOME%\bin"
          MAVEN_OPTS(optional) JVM 설정에 관련된 파라미터
             ex) "-Xms256m -Xmx512m".
    3-2. 기타 환경변수 확인
        JAVA_HOME "C:\Program Files\Java\jdk1.6.0_06"

4. 환경변수 수정(PATH)
    4-1. Maven 환경변수
        Path "%M2%;" 추가
    4-2. 기타 환경변수 확인
        Path "%JAVA_HOME%\bin" 추가



출처: http://lefthand.tistory.com/4 [lefthand's note]

자바에서 JDK / SDK 의미변천사
Java 버전 정책은 참으로 모를일이다..
불필요하게 혼동을 야기하므로 대략적으로 정리해 본다.
(근거자료 from java.net, java.sun.com, official description)

* JDK 1.x :
    JDK 는 "Java Development Kit" 의 축약어로 사용됨.

* JDK 1.2, J2SDK 1.2:
    JDK 는 "J2SE(TM) Development Kit" 의 축약어로 사용됨.
    JAVA 2nd Generation 이란 의미의 "2" 가 사용되기 시작함.
    Sun 의 웹 사이트에 따르면 JDK 보다는 J2SDK, JRE 보다는 J2RE 를 사용하도록 권고 하였으나
    기 사용 개발자들의 인기에 의해 JDK 가 계속 사용되면서 JDK 의 의미는
    "J2SE(TM) Developemnt Kit" 을 나타내게 됨.

   이러한 형태의 사용은 JDK 1.2(J2SDK 1.2) 부터 JDK 1.4.x (J2SDK 1.4.x) 까지 유지됨.

   => Due to significant popularity within the Java developer community,
    the development kit has reverted back to the name "JDK" from "Java 2 SDK" (or "J2SDK"),
    and the runtime environment has reverted back to "JRE" from "J2RE".
    Notice that "JDK" stands for "J2SE Development Kit".
    The name "Java Development Kit" has not been used since 1.1, prior to the advent of J2EE and J2ME.

* JDK 5.0, JDK 5, JDK 1.5.0, JDK 1.5:
    JDK 는 "Java(TM) SE Developement Kit" 의 의미로 사용됨.
    Java2 에서 2 제거됨. Java 를 강조하기 위해 TM 위치를 옮김 (J2SE(TM)->Java(TM) SE)
    제품버전 (Product Version)과 개발버전 (Release Version) 을 따로 가져가기 시작
    제품버전은 5.0 (or 5), 개발버전은 1.5.0 (or 1.5)
    즉, J2SDK 5.0 을 설치하고 java -version 하면 1.5.0 리턴

* Java EE 5 SDK:
    SDK 는 "Java(TM) EE" 를 표현하기 위해서만 사용됨.
    Version 5.0 부터는 SDK 는 JDK 와 의미가 완전히 분리되어 EE 용으로만 사용됨.

* JDK 6:
    JDK 는 "Java(TM) SE Developement Kit" 의 의미로 사용됨.
    버전 표기를 한자리로 사용,
    JDK 6.0 은 사용안함, 단, 기존 사용되는 JDK 5.0 은 JDK 5 와 혼용하여 사용함.

* Java EE 6 SDK :
    SDK 는 "Java(TM) EE" 를 표현하기 위해서만 사용됨.


또 언제 바뀔지 모르지만 ^^



출처: http://lefthand.tistory.com/3 [lefthand's note]

JDK & JRE 차이
JRE 와 JDK 에 대한 차이이다. 알고보면 당연한 것임..

JDK 설치시에 JRE 가 함께 설치되므로 따로 JRE 를 설치할 필요는 없다.
Java 개발을 하지 않고 Application Server 만 운영한다면 JRE 만 설치하면 된다.

(from jGuru.com)

The "JRE" is the Java Runtime Environment. I.e.,
the JRE is an implementation of the Java Virtual Machine which actually executes Java programs.
The java programming language adds the portability by converting the source code to byte code version which can be interpreted by the JRE and gets converted to the platform specific executable ones. Thus for different platforms one has corresponding implementation of JRE. But JRE has to meet the specification JVM (Java Virtual Machine) Concept that serves as a link between the Java libraries and the platform specific implementation of JRE. Thus JVM helps in the abstraction of inner implementation from the programmers who make use of libraries for their programmes.

The "JDK" is the Java Development Kit. I.e.,
the JDK is bundle of software that you can use to develop Java based software.
The JDK comes along with java libraries and JVM embedded in it.

Typically, each JDK contains one (or more) JRE's along with the various development tools
like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.



출처: http://lefthand.tistory.com/2 [lefthand's note]

maven 2 기본(2) - POM
(by http://maven.apache.org/guides/introduction/introduction-to-the-pom.html)

POM (Project Object Model) ?

maven 2 에서 사용되는 작업 단위이다.
pom.xml 이라는 이름의 xml 파일이며, 각각의 프로젝트 빌드와 설정에 사용되는 많은 값들이 기술된다.
maven 1 에서 사용되는 project.xml 은 maven 2 부터는 pom.xml 로 대체되며,
maven 1 에서 프로젝트 플러그인 들의 goal 을 기술하기 위해 사용된 maven.xml 은 pom.xml 에 기술된다.
maven 은 task 나 goal 을 실행시키기 위해서 pom.xml 을 참조한다.

Super POM ?

Super POM 은 maven 의 디폴트 POM 이며 각각의 프로젝트에 생성되는 POM 들은 Super POM 으로 부터 모든 값을 상속받는다.

POM 의 최소 구성요소

* project root
* modelVersion - should be set to 4.0.0
* groupId - the id of the project's group.
* artifactId - the id of the artifact (project)
* version - the version of the artifact under the specified group

Fully qualified artifact name ?

artifact 를 구분하기 위한 full name 이다.
<groupId>:<artifactId>:<version> 형태


Project Inheritance

maven 에서 관리하는 sub project 들 간에 POM 을 상속시킬 수 있다.
child pom 은 parent pom 의 속성을 상송받고, 자기 속성을 추가/변경 할 수 있다.
(자세한 예는 http://maven.apache.org/guides/introduction/introduction-to-the-pom.html 의 project inheritance 참고)

Project Aggregation

maven 에서 관리하는 sub project 들의 POM 을 병합시킬 수 있다.
하위 POM 을 병합할 parent POM 에서는 <packaging>pom</packaging> section 을 추가한다.
parent POM 에서는 <modules></modules> section 을 추가하여 하위 POM 들을 병합한다.
(자세한 예는 http://maven.apache.org/guides/introduction/introduction-to-the-pom.html 의 project inheritance 참고)



출처: http://lefthand.tistory.com/6 [lefthand's note]

maven 2 기본(3) - archetype
What's archetype ?

archetype 은 비슷한 종류의 프로젝트들이 생성될 때 기반이 되는 프로젝트 템플릿 이다.
(http://maven.apache.org/guides/introduction/introduction-to-archetypes.html)
maven 은 archetype 에 따른 작업을 수행하기 위해 archetype이라는 플러그인을 제공한다.
archetype 플러그인은 다음의 4개의 goal 을 정의한다.

 [goals]
 * archetype:create
  프로젝트 템플릿을 생성한다.
  -DarchetypeArtifactId=[archetypeArtifactId] 을 파라미터로 전달하여 특정 프로젝트 템플릿을 생성하며
  archetypeArtifactId 를 지정하지 않은 경우 기본값은 maven-archetype-quickstart 이다.
  maven 2 에서는 사용이 권장되지 않고 archetype:generate 를 사용한다.
 * archetype:generate
  사용자가 프로젝트 템플릿 종류(아래 archetypeArtifactId 목록 참고)를 선택 후 프로젝트를 생성한다.
  선택된 타입은 remote에서 다운로드 되고, 다운로드 완료되면 local 에 프로젝트를 생성한다.
 * archetype:create-from-project
  기존에 작성된 project 로부터 archetype 을 생성한다.
 * archetype:crawl
  maven 2 repository 를 검색하여 archetype 의 목록파일을 생성/업데이트 한다.

ex)
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-webapp


archetypeArtifactId 목록

현재 사용 가능한 archetype 목록이다.
archetype:create 로 생성시에는 maven-archetype-quickstart 가 디폴트로 생성된다.

1: appfuse-basic-jsf
  (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: appfuse-basic-spring
  (AppFuse archetype for creating a web application with Hibernate, Spring and SpringMVC)
3: appfuse-basic-struts
  (AppFuse archetype for creating a web application with Hibernate, Spring and Struts2)
4: appfuse-basic-tapestry
  (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: appfuse-core
  (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: appfuse-modular-jsf
  (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF)
7: appfuse-modular-spring
  (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC)
8: appfuse-modular-struts
  (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2)
9: appfuse-modular-tapestry
  (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4)
10: maven-archetype-j2ee-simple
  (A simple J2EE Java application)
11: maven-archetype-marmalade-mojo
  (A Maven plugin development project using marmalade)
12: maven-archetype-mojo
  (A Maven Java plugin development project)
13: maven-archetype-portlet
   (A simple portlet application)
14: maven-archetype-profiles
  ()
15: maven-archetype-quickstart
  ()
16: maven-archetype-site-simple
  (A simple site generation project)
17: maven-archetype-site
  (A more complex site project)
18: maven-archetype-webapp
  (A simple Java web application)
19: struts2-archetype-starter
  (A starter Struts 2 application with Sitemesh, DWR, and Spring)
20: struts2-archetype-blank
  (A minimal Struts 2 application)
21: struts2-archetype-portlet
  (A minimal Struts 2 application that can be deployed as a portlet)
22: struts2-archetype-dbportlet
  (A starter Struts 2 portlet that demonstrates a simple CRUD interface with db backing)
23: struts2-archetype-plugin
  (A Struts 2 plugin)
24: shale-archetype-blank
  (A blank Shale web application with JSF)
25: maven-adf-archetype
  (Archetype to ease the burden of creating a new application based with ADF)
26: data-app
  (A new Databinder application with sources and resources.)
27: jini-service-archetype
  (Archetype for Jini service project creation)
28: softeu-archetype-seam
  (JSF+Facelets+Seam Archetype)
29: softeu-archetype-seam-simple
  (JSF+Facelets+Seam (no persistence) Archetype)
30: softeu-archetype-jsf
  (JSF+Facelets Archetype)
31: jpa-maven-archetype
  (JPA application)
32: spring-osgi-bundle-archetype
  (Spring-OSGi archetype)
33: confluence-plugin-archetype
  (Atlassian Confluence plugin archetype)
34: jira-plugin-archetype
  (Atlassian JIRA plugin archetype)
35: maven-archetype-har
  (Hibernate Archive)
36: maven-archetype-sar
  (JBoss Service Archive)
37: wicket-archetype-quickstart
  (A simple Apache Wicket project)
38: quickstart
  (A simple Apache Tapestry 5 Project)
39: scala-archetype-simple
  (A simple scala project)
40: lift-archetype-blank
  (A blank/empty liftweb project)
41: lift-archetype-basic
  (The basic (liftweb) project)
42: cocoon-22-archetype-block-plain
  ([http://cocoon.apache.org/2.2/maven-plugins/])
43: cocoon-22-archetype-block
  ([http://cocoon.apache.org/2.2/maven-plugins/])
44: cocoon-22-archetype-webapp
  ([http://cocoon.apache.org/2.2/maven-plugins/])

sns신고


출처: http://lefthand.tistory.com/7 [lefthand's note]



댓글 없음:

댓글 쓰기