1. 특정 라이브러리에서 제공하는 클래스를 사용하도록 소스를 변경합니다.
C:\Users\kdyoung\myapp\MyMavenTest\src\main\java\org\samples\java\App.java
---------------------------------------------------------------------------------------------------------
package org.samples.java;
import org.slf4j.*;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
//System.out.println( "Hello World!" );
Logger logger = LoggerFactory.getLogger(App.class);
logger.info( "Hello World!" );
}
}
import org.slf4j.*;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
//System.out.println( "Hello World!" );
Logger logger = LoggerFactory.getLogger(App.class);
logger.info( "Hello World!" );
}
}
---------------------------------------------------------------------------------------------------------
2. 소스 컴파일을 시도합니다.
-> C:\Users\kdyoung\myapp\MyMavenTest>mvn compile
[INFO] Compiling 1 source file to C:\Users\kdyoung\myapp\MyMavenTest\target\clas
ses
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] C:\Users\kdyoung\myapp\MyMavenTest\src\main\java\org\samples\java\App.java:[3,0] package org.slf4j does not exist
[ERROR] C:\Users\kdyoung\myapp\MyMavenTest\src\main\java\org\samples\java\App.java:[14,2] cannot find symbol
symbol : class Logger
location: class org.samples.java.App
[ERROR] C:\Users\kdyoung\myapp\MyMavenTest\src\main\java\org\samples\java\App.java:[14,18] cannot find symbol
symbol : variable LoggerFactory
location: class org.samples.java.App
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
3. pom.xml을 수정하여 dependency를 추가합니다.
Maven Repository Search 사이트중 하나(예, http://mvnrepository.com/)로 이동하여 "slf4j"를 검색하고 slf4j API Module 링크로 이동합니다.
결과 중 하나를 선택하여 클릭합니다.
상세 내용에서 Maven관련 정보를 Copy합니다.
복사한 내용을 pom.xml에 붙여넣기를 합니다.
C:\Users\kdyoung\myapp\MyMavenTest\pom.xml
---------------------------------------------------------------------------------------------------------
<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.samples.java</groupId>
<artifactId>MyMavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyMavenTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
</project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.samples.java</groupId>
<artifactId>MyMavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyMavenTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
</project>
---------------------------------------------------------------------------------------------------------
junit과 달리 scope를 지정하지 않으면 디폴트로 compile 단계로 scope이 지정됩니다.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version> <scope>compile</scope>
</dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version> <scope>compile</scope>
</dependency>
-> C:\Users\kdyoung\myapp\MyMavenTest>mvn compile
[INFO] ------------------------------------------------------------------------
[INFO] Building MyMavenTest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.pom (3 KB at 1.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/1.7.5/slf4j-parent-1.7.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/1.7.5/slf4j-parent-1.7.5.pom (12 KB at 28.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar (26 KB at 44.6 KB/sec)
[INFO] Compiling 1 source file to C:\Users\kdyoung\myapp\MyMavenTest\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
댓글 없음:
댓글 쓰기