728x90
반응형
728x90
반응형

javac를 이용해 class파일 생성도중 아래와 같은 오류가 발생하였는데요.

unmappable character for encoding MS949

구글링해보니 컴파일시 오류로 인코딩을 지정해줘야 한다고 하네요.

또는 해당 파일의 인코딩을 UTF-8로 변경하는 것도 방법일 수 있겠네요.

 

1. 윈도우

javac extract.java -encoding UTF-8

2. 리눅스

/자바 설치경로/bin/javac -encoding UTF-8 ./extract.java

 

728x90
반응형
728x90
반응형

개발 하다보면 특정 날짜에 요일을 알아내야 하는 경우가 생깁니다.

자바에서 특정 날짜에서 요일 구하는 메소드 알아보겠습니다.

/**
 * 특정 날짜 요일 구하기
 * @param date
 * @param dateType
 * @return
 * @throws Exception
 */
public String getDateDay(String date, String dateType) throws Exception {
    String day = "" ;
     
    //SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
    //SimpleDateFormat date1 = new SimpleDateFormat("yyyyMMdd");
    //SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
    SimpleDateFormat dateFormat = new SimpleDateFormat(dateType) ;
    Date nDate = dateFormat.parse(date) ;
     
    Calendar cal = Calendar.getInstance() ;
    cal.setTime(nDate);
     
    int dayNum = cal.get(Calendar.DAY_OF_WEEK) ;
    
    switch(dayNum){
        case 1:
            day = "일";
            break ;
        case 2:
            day = "월";
            break ;
        case 3:
            day = "화";
            break ;
        case 4:
            day = "수";
            break ;
        case 5:
            day = "목";
            break ;
        case 6:
            day = "금";
            break ;
        case 7:
            day = "토";
            break ;
             
    }
    return day ;
}
728x90
반응형
728x90
반응형

개발하면서 서비스 장애로 인해 덤프 파일을 분석해야할 일이 있습니다.

덤프 파일 생성 후 분석하는 방법에 대해 간단히 알아보겠습니다.

 

0. 프로세스 pid 조회하기

 : ps -ef | grep java

 : 실행중인 자바 프로세스 확인하는 명령어

 

1. 힙 덤프 (Heap dump)

 : 덤프 파일의 확장자는 .hprof

 jmap -dump:format=b,file=[덤프파일이름]_dump.hprof pid

 

힙덤프 분석 tool - Eclipse Memory Analyzer (MAT)

1) Eclipse Memory Analyzer (MAT) 다운받기

 : www.eclipse.org/mat/downloads.php

 

Eclipse Memory Analyzer Open Source Project | The Eclipse Foundation

The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 375 open source projects, including runtimes, tools and frameworks.

www.eclipse.org

 : OS버전에 맞게 다운

 

2) 사용법

 : spoqa.github.io/2012/02/06/eclipse-mat.html

 

Eclipse Memory Analyzer 소개

Eclipse Memory Analyzer(MAT)을 소개하고 유용하게 쓸 수 있는 기능들을 알아봅니다.

spoqa.github.io

2.  스레드덤프 (Thread dump)

 jstack -l pid >> [덤프파일이름]_thread_dump.log

 

2-1)스레드덤프 분석 사이트

fastthread.io/ft-index.jsp

 

fastthread.io

Thread Dump Analysis REST API In this modern world, thread dumps are still analyzed in a tedious & manual mode. i.e., Operations engineer captures thread dumps from the production servers; then he transmits those files to developers. Developers use thread

fastthread.io

3. 프로세스 스택 (pstack)

pstack은 프로세스의 스택 정보를 보여주는 명령어입니다.

쓰레드의 상태를 확인하는 용도로 사용합니다.

pstack $pid >> [프로세스스택명]_pstack.txt

728x90
반응형
728x90
반응형

자바에서 Byte 배열로 문자열 자르는 방법에 대해 알아보겠습니다.

고객사에서 SMS서비스를 사용하여 DB에 insert를 해주는 로직이 있는데,

SMS에서 최대 발송 길이 제한이 있다고하여 밸리데이션을 추가해주었습니다.

String a = "ABCDEFGHIJK";
int msgByteCheck = a.getBytes("UTF-8").length; // a의 문자열 길이
String subA = getMaxByteString(a, 5); 

//str = 문자열
//maxLen = 자를 길이
public static String getMaxByteSubString(String str, int maxLen) throws UnsupportedEncodingException {
	StringBuilder sb = new StringBuilder();
	int curLen = 0;
	String curChar;
        
	for (int i = 0; i < str.length(); i++) {
		curChar = str.substring(i, i + 1);
		curLen += curChar.getBytes("UTF-8").length;
		if (curLen > maxLen)
			break;
        else
            sb.append(curChar);
        }
	return sb.toString();
}

 

728x90
반응형
728x90
반응형

 

java.lang.UnsupportedClassVersionError: Bad version number in .class file 오류 해결하는 방법에 대해 알아보겠습니다.

아래와 같은 오류는 컴파일 버전이 다르기 때문에 발생하는 것입니다.

이클립스 -> window -> Preferences -> Java -> Compiler 에서 jdk 버전에 맞게 변경 후 컴파일 해주시면 됩니다.

 

 

728x90
반응형
728x90
반응형

class파일을 jar파일로 압축하는 방법에 대해 알아보겠습니다.

1. cmd 명령프롬프트 창을 엽니다.

2. 압축하고자 하는 폴더로 이동합니다.

3. 폴더로 이동했다면 아래의 명령어를 입력합니다.

  주의할 점은 . 을 빼면 안됩니다.

 jar cvf catalina.jar .

catalina.jar 파일이 생성되었습니다.

728x90
반응형
728x90
반응형

자바 string타입을 date타입으로 변환하는 법에 대해 알아보겠습니다.

ex) yyyymmdd

 

 

	String sDate = "20190428";
    String eDate = "20190505";
    String startDate = "";
    String endDate = "";
    
	SimpleDateFormat beforeFormat = new SimpleDateFormat("yyyymmdd");
	//Date로 변경하기 위해 날짜 형식을 yyyy-mm-dd로 변경
	SimpleDateFormat afterFormat = new SimpleDateFormat("yyyy-mm-dd");
	Date tempDate = null;
	Date tempDate2 = null;
		    
	//yyyymmdd로된 날짜 형식으로 java.util.Date객체를 만듬
	tempDate = beforeFormat.parse(sDate);
	tempDate2 = beforeFormat.parse(eDate);
		   
	//Date를 yyyy-mm-dd 형식으로 변경하여 String으로 반환
	startDate = afterFormat.format(tempDate);
	endDate = afterFormat.format(tempDate2);
    
    System.out.println("startDate: " + startDate); // 2019-04-28
    System.out.println("endDate: " + endDate); // 2019-05-05
728x90
반응형
728x90
반응형

해당 오류는 톰캣 구동 시 포트 번호가 일치하지 않아서 발생한 오류 입니다.


연결하려는 호스트 이름 및 포트를 확인해주시면 됩니다.



728x90
반응형
728x90
반응형

+ Recent posts