Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

Fix you

네트워크가 안되는 환경에서 로컬 레파지토리로 바꿔서 빌드환경 바꾸기 본문

Spring

네트워크가 안되는 환경에서 로컬 레파지토리로 바꿔서 빌드환경 바꾸기

frjufvjn 2018. 9. 22. 15:15

인터넷이 가능한 개발환경에서 개발후에 

개발한 패키지를 인터넷이 불가능한 개발환경인 서버로 올리고 나면

로컬 메이븐 레파지토리를 활용하여 빌드 할 수 있게 바꿔야 합니다. 


다른 방법이 있으시면 댓글 주시면 감사하겠습니다.


1. 우선 이클립스의 Package Explorer에서 Maven Dependencies아래의 jar들을 선택한후 

마우스 우클릭하여 Copy합니다.



2. 카피한 문자열은 아래와 같이 피시의 유저 디렉토리의 공용 레파지토리로 되어 있을 것입니다. 

프로젝트 디렉토리 안에 가져올 필요가 있습니다.


C:\Users\PJW\.m2\repository\org\springframework\boot\spring-boot-starter-web\1.1.1.RELEASE\spring-boot-starter-web-1.1.1.RELEASE.jar

C:\Users\PJW\.m2\repository\org\springframework\boot\spring-boot-starter\1.1.1.RELEASE\spring-boot-starter-1.1.1.RELEASE.jar

C:\Users\PJW\.m2\repository\org\springframework\boot\spring-boot\1.1.1.RELEASE\spring-boot-1.1.1.RELEASE.jar

... 생략


3. 일일이 하기 힘드니 자바코드로 마이그레이션 해봅시다. 

프로젝트 디렉토리 lib 디렉토리 안에 레파지토리로 불러올 수 있는 구조 그대로 옮겨집니다. 

public static void main( String[] args ) {
String[] libs = {
"C:\Users\PJW\.m2\repository\org\springframework\boot\spring-boot-starter-web\1.1.1.RELEASE\spring-boot-starter-web-1.1.1.RELEASE.jar",
"C:\Users\PJW\.m2\repository\org\springframework\boot\spring-boot-starter\1.1.1.RELEASE\spring-boot-starter-1.1.1.RELEASE.jar",
"C:\Users\PJW\.m2\repository\org\springframework\boot\spring-boot\1.1.1.RELEASE\spring-boot-1.1.1.RELEASE.jar"
};
for (int i = 0; i < libs.length; i++) {
String targetPath = libs[i].replace("C:/Users/PJW/.m2/repository", "C:/workspace_spring/vertx-mybatis/lib");
String tmp[] = targetPath.split("/");
String tmpPath = targetPath.replace(tmp[tmp.length-1], "");
File file = new File(tmpPath);
if(!file.exists()){
file.mkdirs();
}
fileCopy(libs[i], targetPath);
}

private static boolean fileCopy(String in, String out) {
try ( FileInputStream inputStream = new FileInputStream(in);
FileOutputStream outputStream = new FileOutputStream(out);
FileChannel fcin = inputStream.getChannel();
FileChannel fcout = outputStream.getChannel() ) {
long size = fcin.size();
fcin.transferTo(0, size, fcout);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
}




4. 이제 pom.xml만 고치면 됩니다.
지금 수정한 pom.xml은 별도의 pom.xml 복사본을 만들어서 서버에 올릴때 사용하고
원래 수정전 pom.xml은 피시에서 그대로 씁니다.

<repositories>
<!-- Local Repository -->
<repository>
<id>local-repo</id>
<name>local Repository</name>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>