IT/maven

maven - 라이브러리 만들기

노마드오브 2018. 11. 24. 21:57

메이븐 

로컬저장소, 중앙저장소, 원격저장소


mvn-lib 프로젝트

mvn clean ==> target 지우기

mvn package ==> target 안에 jar 만들어짐

mvn install ==> 로컬 저장소에 저장


mvn-app2 pom.xml에 dependency 추가

.m2에 가보면 mvn-lib 가 추가되어있음



mvn-lib 프로젝트

package com.example.lib;


public class Lib {

private String msg = "";

public Lib(String msg) {

this.msg = msg;

}

public String getMessage() {

return "\n=================\n" + msg + 

"\n=================\n";

}


@Override

public String toString() {

return "MSG : " + this.msg;

}

}




mvn-app2 프로젝트

package com.example;



import com.example.lib.Lib;


public class App 

{

    public static void main( String[] args )

    {

        Lib lib = new Lib("Hello~~~~!");

        System.out.println(lib.getMessage());

    }

}




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


<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.example</groupId>

  <artifactId>mvn-app2</artifactId>

  <version>1.0-SNAPSHOT</version>


  <name>mvn-app2</name>

  <!-- FIXME change it to the project's website -->

  <url>http://www.example.com</url>


  <properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <maven.compiler.source>1.7</maven.compiler.source>

    <maven.compiler.target>1.7</maven.compiler.target>

  </properties>


<repositories>

<repository>

<id>spring.org</id>

<name>spring foundation repository</name>

<url>http://repo.spring.io/release/</url>

</repository>

</repositories>


  <dependencies>

  <dependency>

  <groupId>com.example</groupId>

  <artifactId>mvn-lib</artifactId>

  <version>1.0-SNAPSHOT</version>

  </dependency>

  <dependency>

  <groupId>org.aspectj</groupId>

  <artifactId>aspectjrt</artifactId>

  <version>1.6.10.RELEASE</version>

  </dependency>

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>4.11</version>

      <scope>test</scope>

    </dependency>

  </dependencies>


  <build>

    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->

      <plugins>

        <plugin>

          <artifactId>maven-clean-plugin</artifactId>

          <version>3.0.0</version>

        </plugin>

        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->

        <plugin>

          <artifactId>maven-resources-plugin</artifactId>

          <version>3.0.2</version>

        </plugin>

        <plugin>

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

          <version>3.7.0</version>

        </plugin>

        <plugin>

          <artifactId>maven-surefire-plugin</artifactId>

          <version>2.20.1</version>

        </plugin>

        <plugin>

          <artifactId>maven-jar-plugin</artifactId>

          <version>3.0.2</version>

        </plugin>

        <plugin>

          <artifactId>maven-install-plugin</artifactId>

          <version>2.5.2</version>

        </plugin>

        <plugin>

          <artifactId>maven-deploy-plugin</artifactId>

          <version>2.8.2</version>

        </plugin>

      </plugins>

    </pluginManagement>

  </build>

</project>