apache common 의 라이브러리를 이용하면 아주 쉽게 쉘이나, cmd 에서의 명령어 수행이 가능하다.

 

1. pom.xml 에 추가

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-exec</artifactId>
    <version>1.3</version>
</dependency>

 

 

2. 메소드 구현

public void runPdf2htmlEx(String fileNm) throws Exception {
    String[] command = {html2pdfEX, fileNm};

    DefaultExecutor executor = new DefaultExecutor();
    CommandLine cmdLine = CommandLine.parse(command[0]);
    for (int i = 1, n = command.length; i < n; i++) {
        cmdLine.addArgument(command[i]);
    }
    log.debug("cmdLine : " + cmdLine.toString());

    // 동시 실행

    executor.execute(new CommandLine(cmdLine), new DefaultExecuteResultHandler());

    // 개별로 실행 ( 하나가 끝나야 다음거를 수행함)

    // executor.execute(cmdLine);
    executor.setExitValue(1);

}

 

 

'자바' 카테고리의 다른 글

특정 파일 포멧만 선택 하여 작업하기  (0) 2021.04.28
자바에서 프로그램 수행 시간 측정  (0) 2021.04.28

FileFilter 를 사용하여 특정 파일 포멧만 필터링이 가능하다.

 

예제)

File dir = new File(param.getInFileNm());
FileFilter filter = f -> f.getName().endsWith("pdf");

File files[] = dir.listFiles(filter);
for (int i = 0; i < files.length; i++) {

    pdf2HtmlExService.runPdf2htmlEx(files[i].getAbsoluteFile().toString());
}

 

 

 

'자바' 카테고리의 다른 글

쉘, 커멘드 명령어 실행 방법  (0) 2021.04.28
자바에서 프로그램 수행 시간 측정  (0) 2021.04.28

측정을 하고 싶은곳에서 

long start = System.currentTimeMillis()

.

.

.

.

long total = (System.currentTimeMillis() - start) / 1000;

log.info("total time : " + total + " sec...");

 

이러면 시간 측정이 가능

'자바' 카테고리의 다른 글

쉘, 커멘드 명령어 실행 방법  (0) 2021.04.28
특정 파일 포멧만 선택 하여 작업하기  (0) 2021.04.28

+ Recent posts