• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Maven 배포시 Local Jar 파일과 함께 하기!

31 Dec 2018

Reading time ~1 minute

오랜만에 JAVA로 개발 했다.

Node에서 Oracle JDBC에 연결을 하려는데 기존 버젼과 충돌이 발생하였다.

이를 해결하기 위해 기존 버젼을 변경에 따르는 사이드 임펙트를 알지 못하기에, JAVA를 이용하기로 하였다.

문제는 MAVEN에서 ojdbc 관련해서 dependency를 설정해도 가져오지를 못했다. 망할 오라클이 문제인가…

우여곡절 끝에 해당 jar 파일을 다운 받아 dependency를 다음과 같이 설정 하였다.

# pom.xml
...생략
<dependency>
    <groupId>oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.3</version>
    <scope>system</scope>
    <systemPath>file://${project.basedir}/lib<systemPath>
</dependency>
...생략

이렇게 처리 할 경우, 패키징을 할때 해당 jar 파일이 함께 배포 되지 않는다.

이럴때 쉬운 방법으로 로컬 저장소를 이용하면 된다.

먼저 pom.xml에 로컬 저장소를 다음과 같이 추가한다.

# pom.xml
...생략
<dependency>
    <groupId>oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.3</version>
</dependency>
...생략
<repositories>
    <repository>
        <id>local-repository</id>
        <name>local repository</name>
        <url>file://${project.basedir}/lib</url>
    </repository>
</repositories>
...생략

이후 해당 디렉토리에 jar를 다음과 같은 형태로 추가 한다.

Local Repository
# 아래과 같은 형식으로 디렉토리 구조를 만들어야 한다.
lib/
  {groupId}/
    {ojdbc6}/
      {version}/
        ojdbc6-11.2.0.3.jar

마지막으로, 신나게 패키징을 하려는데 무료 IntelliJ를 써서 제대로 지원이 안되나 보다.

mvn install spring-boot:repackage

... 생략
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage (default-cli) on project simple-api: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage failed: Source file must be provided -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

이걸 해결 하기 위해서 RUN > Edit Configuration 창을 열어서 Maven Run을 추가 했다.

RUN > Edit Configuration

명령어에 mvn을 넣으면 안된다.

# -U 옵션은 로컬 리포지토리 사용시 추가하는 옵션이다.
package spring-boot:repackage -U

오늘의 삽질 끝~

새해복 많이 받자!

참고 자료

  • IntelliJ mvn package is behaving differently that command line
  • [Maven] local jar를 dependency 추가하기


mavenjar Share Tweet +1