티스토리 페이스복 연동

카테고리 없음 2011. 2. 18. 10:08 Posted by coodnoob
티스토리에서 제공해주는 플러그인 중

Tistory2Facebook 플러그인을 사용



설정에서 계정을 연결하고

글을 쓰면 Facebook 담벼락에 글을 올릴 수 있다.

단. 글의 상태는 공개 + 발행 상태이여야 한다.

나머지(비공개, 보호, 공개 + 비발행)는 안 됩니다.


Maven POM

카테고리 없음 2011. 1. 19. 14:18 Posted by coodnoob
POM 이란

Project Object Model 로서 메이븐에서 사용하는 프로젝트 관리를 위한 모델이다.
보통 프로젝트의 루트에 pom.xml 파일에서 관리하는데 
여기서 관리하는 내용은 현재 기본적인 프로젝트의 정보, 빌드 세팅, 부가적인 프로젝트 정보, 환경 설정등이 있다.

1. 프로젝트의 기본 정보

<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.codehaus.mojo</groupId>  <artifactId>my-project</artifactId>  <version>1.0</version></project>

여기서는 현재 프로젝트에 대한 기본적인 정보들을 기술한다.

엘리먼트 소개
<groupId> : groupId는 일반적으로 유니크한 값을 사용한다. 이것의 이름은 레포지토리의 폴더에 영향을 미치게된다.
<artifactId> : artifactId는 프로젝트의 잘 알려진 이름을 적는다. groupId와 함께 프로젝트를 유니크하게 할 수 있는 값이다.
<version> : version은 현재 버전을 말하는데 groupId, artifactId와 함께 레포지토리의 디렉토리를 구축하는데 같이 쓰인다.
예를들면 로컬레포지터리에 groupId\artifactId\version 이런식으로 폴더가 구성된다. groupId에 . 가 들어가면 그 해당 앞뒤 단어도 각각 다른 폴더로 지정된다.
<packaging> : packaging은 현재 프로젝트의 배포할 타입 포맷을 지정한다. 디폴트는 jar이다.

2. 디펜던시 관리

<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"> ... <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.0</version> <type>jar</type> <scope>test</scope> <optional>true</optional> </dependency> ... </dependencies> ...</project>

groupId와 artifactId와 version은 위에서 설명한 내용과 같다.
<type> artifact의 패키지된 타입을 기술한다.
<scope> scope는 작업상태(compiling and runtime, testing, etc)의 클래스패스와 관련되어 있을 뿐만 아니라 디펜던시의 이행성을 얼마만큼 허용할 것인가를 관리한다.
  • compile - this is the default scope, used if none is specified. Compile dependencies are available in all classpaths. Furthermore, those dependencies are propagated to dependent projects.
  • provided - this is much like compile, but indicates you expect the JDK or a container to provide it at runtime. It is only available on the compilation and test classpath, and is not transitive.
  • runtime - this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
  • test - this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.
  • system - this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

  • <exclusions> exclusions 엘리먼트는 해당 모듈을 제외할 때 사용된다.

    <dependencies>
        <dependency>      <groupId>org.apache.maven</groupId>      <artifactId>maven-embedder</artifactId>      <version>2.0</version>      <exclusions>
            <exclusion>          <groupId>org.apache.maven</groupId>          <artifactId>maven-core</artifactId>        </exclusion>
    </exclusions> </dependency>
    <Parent pom.xml>

    Inheritance
    메이븐은 상속기능을 제공한다.
    상속을 사용하기 위해서는 부모프로젝트의 packaging type은 pom이여야 한다.
    이 패키징 타입들은 라이프사이클의 한부분인 goals을 지정할 때 쓰인다. 예를 들어 패키징 타입이 jar면 패키징 단계의 goals은 jar:jar가 된다.
    패키징이 pom 이라면 site:attach-descriptor 가 된다.
    부모의 엘리먼트들은 자식 엘리먼트들이 상속한다.

    <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> <parent> <groupId>org.codehaus.mojo</groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <relativePath>../my-parent</relativePath> </parent> <artifactId>my-project</artifactId></project>
    <child pom.xml>

    위와 같이 <parent> 엘리먼트를 이용하여 상속 할 대상을 정의할 수 있다.
    <relativePath> 엘리먼트는 필요하지는 않지만 현재 프로젝트의 부모 프로젝트의 경로를 처음으로 검색 할 때 이용된다. 그 다음에 로컬레포지토리와 원격 레포지토리를 
    검색한다.

    The Super POM

    OOP의 객체상속과 비슷하게, POM들은 parent의 값들을 상속을 이용하여 확장할 수 있다. 게다가 자바의 모든 오브젝트가 java.lang.Object 를 상속 하듯이, 모든 POM은
    Super POM을 기본적으로 상속한다.

    mvn help:effective-pom

    이렇게 타이핑 하면 SuperPom이 당신이 만든 프로젝트에서 암묵적으로 쓰인 부분을 확인 할 수 있다.
    프로젝트의 pom.xml파일이 있는 곳에서 해야한다.

    Aggregation(or Multi-Module)
    위와 같이 inherit을 이용하는 다른 모듈과의 관계를 aggregation으로 나타 낼 수 도 있다.
    <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.codehaus.mojo</groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <packaging>pom</packaging> <modules> <module>my-project</module> <module>another-project</module> </modules></project>
    <최상위 pom.xml>
    이 때 패키징 엘리먼트 역시 pom이고
    <modules> 에서 관련된 하위 모듈을 기술한다.
    하위 모듈들에서는 상속에서와 마찬가지로 <parent> 엘리먼트를 이용하여 최상위 모듈을 지정 할 수 있다.

    3. Build Settings
    위에서 주어진 폼의 기본 뿐만 아니라 알 필요가 있는 엘리먼트 들이 더 있다.
    프로젝트의 디렉토리 구조를 선언하고 플러그인을 관리할 수 있는 build 엘리먼트와 reporting을 하기위한 reporting 엘리먼트이다.

    Build
    POM4.0.0 XSD에 의하면 <build> 엘리먼트는 개념적으로 두가지로 나뉜다. 하나는 <project> 밑에서 사용되는 거고 또 다른 하나는 <profiles> 밑에서 사용 하는 것이다.

    <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"> ... <!-- "Project Build" contains more elements than just the BaseBuild set --> <build>...</build> <profiles> <profile> <!-- "Profile Build" contains a subset of "Project Build"s elements --> <build>...</build> </profile> </profiles></project>

    BaseBuild Element Set
    BaseBuild 는 그 단어 뜻 그대로 <build> 엘리먼트 안에서 사용되는 기본적인 elements들이다.
    <build>  <defaultGoal>install</defaultGoal>  <directory>${basedir}/target</directory>  <finalName>${artifactId}-${version}</finalName>  <filters>    <filter>filters/filter1.properties</filter>  </filters>  ...</build>
    • defaultGoal: the default goal or phase to execute if none is given. If a goal is given, it should be defined as it is in the command line (such as jar:jar). The same goes for if a phase is defined (such as install).
    • directory: This is the directory where the build will dump its files or, in Maven parlance, the build's target. It aptly defaults to ${basedir}/target.
    • finalName: This is the name of the bundled project when it is finally built (sans the file extension, for example: my-project-1.0.jar). It defaults to ${artifactId}-${version}. The term "finalName" is kind of a misnomer, however, as plugins that build the bundled project have every right to ignore/modify this name (but they usually do not). For example, if the maven-jar-plugin is configured to give a jar a classifier of test, then the actual jar defined above will be built as my-project-1.0-test.jar.
    • filter: Defines *.properties files that contain a list of properties that apply to resources which accept their settings (covered below). In other words, the "name=value" pairs defined within the filter files replace ${name}strings within resources on build. The example above defines the filter1.properties file under the filter/ directory. Maven's default filter directory is ${basedir}/src/main/filters/.
    Resources
    build 엘리먼트의 다륵 특징은 프로젝트 내에 존재하는 리소스들을 명시 할 수 있다. 리소스는 소스코드가 아니라 컴파일 되지 않으면 다양한 이유로 프로젝트 내에 추가 되는
    그런 것들을 말한다.

    예를 들면 Plexus 프로젝트는 configuration.xml 파일을 필요로 하는데 META-INF/plexus 디렉토리의

    <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">
     
    <build> ... <resources> <resource> <targetPath>META-INF/plexus</targetPath> <filtering>false</filtering> <directory>${basedir}/src/main/plexus</directory> <includes> <include>configuration.xml</include> </includes> <excludes> <exclude>**/*.properties</exclude> </excludes> </resource> </resources> <testResources> ... </testResources> ... </build> </project>
    • resources: is a list of resource elements that each describe what and where to include files associated with this project.
    • targetPath: Specifies the directory structure to place the set of resources from a build. Target path defaults to the base directory. A commonly specified target path for resources that will be packaged in a JAR is META-INF.
    • filtering: is true or false, denoting if filtering is to be enabled for this resource. Note, that filter *.properties files do not have to be defined for filtering to occur - resources can also use properties that are by default defined in the POM (such as ${project.version}), passed into the command line using the "-D" flag (for example, "-Dname=value") or are explicitly defined by the properties element. Filter files were covered above.
    • directory: This element's value defines where the resources are to be found. The default directory for a build is ${basedir}/src/main/resources.
    • includes: A set of files patterns which specify the files to include as resources under that specified directory, using * as a wildcard.
    • excludes: The same structure as includes, but specifies which files to ignore. In conflicts between include and excludeexclude wins.
    • testResources: The testResources element block contains testResource elements. Their definitions are similar to resource elements, but are naturally used during test phases. The one difference is that the default (Super POM defined) test resource directory for a project is ${basedir}/src/test/resources. Test resources are not deployed.
    Plugins
    <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"> <build> ... <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.0</version> <extensions>false</extensions> <inherited>true</inherited> <configuration> <classifier>test</classifier> </configuration> <dependencies>...</dependencies> <executions>...</executions> </plugin> </plugins> </build> </project>

    Beyond the standard coordinate of groupId:artifactId:version, there are elements which configure the plugin or this builds interaction with it.

    • extensionstrue or false, whether or not to load extensions of this plugin. It is by default false. Extensions are covered later in this document.
    • inheritedtrue or false, whether or not this plugin configuration should apply to POMs which inherit from this one.
    • configuration: This is specific to the individual plugin. Without going too in depth into the mechanics of how plugins work, suffice it to say that whatever properties that the plugin Mojo may expect (these are getters and setters in the Java Mojo bean) can be specified here. In the above example, we are setting the classifier property to test in the maven-jar-plugin's Mojo. It may be good to note that all configuration elements, wherever they are within the POM, are intended to pass values to another underlying system, such as a plugin. In other words: values within a configuration element are never explicitly required by the POM schema, but a plugin goal has every right to require configuration values.
    • dependencies: Dependencies are seen a lot within the POM, and are an element under all plugins element blocks. The dependencies have the same structure and function as under that base build. The major difference in this case is that instead of applying as dependencies of the project, they now apply as dependencies of the plugin that they are under. The power of this is to alter the dependency list of a plugin, perhaps by removing an unused runtime dependency via exclusions, or by altering the version of a required dpendency. See above under Dependencies for more information.
    • executions: It is important to keep in mind that a plugin may have multiple goals. Each goal may have a separate configuration, possibly even binding a plugin's goal to a different phase altogether. executionsconfigure the execution of a plugin's goals.
    For example, suppose you wanted to bind the antrun:run goal to the verify phase. We want the task to echo the build directory, as well as avoid passing on this configuration to its children (assuming it is a parent) by setting inherited to false. You would get an execution like this:


    <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"> ... <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>echodir</id> <goals> <goal>run</goal> </goals> <phase>verify</phase> <inherited>false</inherited> <configuration> <tasks> <echo>Build Dir: ${project.build.directory}</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>

    • id: Self explanatory. It specifies this execution block between all of the others. When the phase is run, it will be shown in the form: [plugin:goal execution: id]. In the case of this example: [antrun:run execution: echodir]
    • goals: Like all pluralized POM elements, this contains a list of singular elements. In this case, a list of plugin goals which are being specified by this execution block.
    • phase: This is the phase that the list of goals will execute in. This is a very powerful option, allowing one to bind any goal to any phase in the build lifecycle, altering the default behavior of Maven.
    • inherited: Like the inherited element above, setting this false will supress Maven from passing this execution onto its children. This element is only meaningful to parent POMs.
    • configuration: Same as above, but confines the configuration to this specific list of goals, rather than all goals under the plugin.

    4. Environment Settings

    결론 : The POM is the large, but bright, center.


    참고 한 사이트





























    메이븐 시작 - (5분 정복)

    카테고리 없음 2011. 1. 18. 13:35 Posted by coodnoob
    1.설치

    설치에 앞서 메이븐은 한마디로 빌드 프로세스 자동화 도구 입니다.

    메이븐은 자바 tool이라서 진행에 앞서 자바(JDK)가 설치되어 있어야합니다.

    일단 메이븐을 다운로드 받고 아래와 같은 절차를 따라 설치를 합니다.

    Windows 2000/XP

    1. Unzip the distribution archive, i.e. apache-maven-3.0.2-bin.zip to the directory you wish to install Maven 3.0.2. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectoryapache-maven-3.0.2 will be created from the archive.
    2. Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.0.2. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven < 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
    3. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
    4. Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
    5. In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
    6. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in yourPath environment variable.
    7. Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.

    Unix-based Operating Systems (Linux, Solaris and Mac OS X)

    1. Extract the distribution archive, i.e. apache-maven-3.0.2-bin.tar.gz to the directory you wish to install Maven 3.0.2. These instructions assume you chose /usr/local/apache-maven. The subdirectory apache-maven-3.0.2will be created from the archive.
    2. In a command terminal, add the M2_HOME environment variable, e.g. export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.2.
    3. Add the M2 environment variable, e.g. export M2=$M2_HOME/bin.
    4. Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.
    5. Add M2 environment variable to your path, e.g. export PATH=$M2:$PATH.
    6. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02 and that $JAVA_HOME/bin is in your PATH environment variable.
    7. Run mvn --version to verify that it is correctly installed.
    설치가 끝나면

    mvn -version
    을 입력하여 설치 및 환경설정이 잘 되었나 확인합니다.


    네트워크 setup에 따라 부가적인 설정이 더 필요할 수 있습니다. 그럴 때는 Guide to configuration Maven을 참조하세요.

    2. 프로젝트 생성

    커맨드라인에 다음과 같은 메이븐 goal을 실행 하세요.
    mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    여기서 잠깐
    메이븐은 mvn plugin:goal 이런 형태로 각각의 플러그인(이 플러그인은 메이븐 라이프사이클의 특정 부분들에 매핑되어있다.)에 따른  goal을 명시해 줌으로써 실행할 수 있다.
    위에서 archetype은 goal을 가지고 있는 plugin이고 generate는 archetype에서 실행 할 수 있는 goal들 중 하나이다.

    처음으로 run을 하게 되면 시간이 걸릴 수 있다. 왜냐하면 최신 artifacts들(plugin jars and other files)을 로컬레포지토리로 다운로드하기 때문이다.

    위와 같이 명령어를 실행하면 아래와 같은 형태의 디렉토리가 생성된다.
    my-app |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java

    위에서는 maven-archetype-quickstart 를 이용하여 기본템플릿이 위와 같이 나왔다.

    pom.xml 파일이 메이븐에서 프로젝트설정의 핵심이다. 프로젝트를 원하는대로 빌드하는데 필요로하는 메인 정보들을 가진 하나의 설정 파일이다. POM은 매우 거대하고 이것의 복잡함으로 인해 지레 겁을먹을 수 있다. 하지만 지금 효과적으로 사용하기 위해 복잡성을 이해하는 것은 불필요하다.

    위에서 만든 프로젝트의 POM은 다음과 같다.

    <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>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>Maven Quick Start Archetype</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>

    여기서 
    gruopId는 프로젝트의 그룹 ID이고 일반적으로 패키지이름처럼 사용하는거 같다.
    artifactId는 artifact의 고유ID이다.
    vesrsion은 version개발 중일때는 SNAPSHOT을 붙여쓴다.
    packaging 은 패키징 타입(jar 같은)
    dependencies는 이 프로젝트에서 의존하는 다른 모듈을 정의한다
    하위 엘리먼트중에 나머지는 위와 같고 scope는 의존하는 범위를 설정한다. (ex: compile(디폴트), runtime(실행할때 필요 결국 배포할때 필요), provided(기본적으로 제공되는 모듈 배포시 제외), test(테스트시 필요 배포시 제외))


    3. Build the Project

    mvn package

    아까와는 달리 무언가 커맨드가 단순해진 것을 알 수 있다. 
    goal 을 없애고 phase를 사용하였는데 phase는 빌드 라이프 사이클의 한단계를 의미한다. (메이븐은 ANT와는 달리 자신만의 빌드라이프사이클이 존재한다.)
    결국 하나의 phase는 plugin이 디폴트로 매핑되어있어 실행한다.

    이렇게 실행을 하면
    1. validate
    2. generate-sources
    3. process-sources
    4. generate-resources
    5. process-resources
    6. compile
    위와 같은 빌드라이프 사이클을 순서대로 실행하고 마지막으로 jar 파일을 생성해준다.

    아래와 같이 커맨드를 입력하면 테스트 해 볼 수 있다.

    java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
    

    결과:

    Hello World!

    4. Maven Phases

    메이븐의 라이프 사이클은 크게 세가지로 구성되어있다.
    default lifecycle, clean lifecycle, site lifecycle

    default lifecycle의 phase는 다음과 같다.은 다음과 같이 구성되어있다.
    • validate: 프로젝트가 오류가 없는지 필요한 정보가 사용가능한지 체크한다.
    • compile: 프로젝트의 소스코드를 컴파일한다.
    • test: 유닛테스트 프로엠워크를 이용하여 컴파일된 소스를 테스트한다. 
    • package: 컴파일된 코드를 가지고와서 배포될 포맷으로 패키징한다.
    • integration-test: 통합테스트가 가능한 환경으로 패키지를 배포한다.
    • verify: 패키지가 유효한지, 기준에 적합한지 검증한다.
    • install: 패키지를 로컬레포지토리에 인스톨한다.
    • deploy: 패키지를 원격레포지토리로 카피한다. 
    clean lifecycle은
    • clean:
      기존에 빌드된 산출물들을 제거한다.

    site lifecycle은
    • site:
      이 프로젝트를 위한 사이트 문서를 생성한다.

    알아두어야 할 점은 만약 package phase를 실행하였으면 디폴트 라이프 사이클 바인딩에 따라 기존phase들이 순차적으로 실행된다.


    참고 사이트 :