Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 오류
- awscli
- 개발
- compositekey
- 테스트코드
- Route53
- 다이나모디비
- 스프링테스트
- filterexpression
- 스프링
- 자바
- awscloud
- secondaryindex
- markerinterface
- Springsecurity
- query
- annotation
- EmbeddedId
- testresttemplate
- partiql
- Java
- Spring
- MockMvc
- DynamoDB
- 자바스프링
- 도메인
- 로드밸런서
- javaspring
- AWS
- IdClass
Archives
- Today
- Total
아장아장 개발 일기
Jar 파일 PathNotFound 오류 해결 방법 본문
IntelliJ에서 프로그램을 실행시켰을땐 잘 찾아지던 file이 Jar파일로 만든후 해당 파일을 찾으려하면 FileNotFound Exception이 발생했다.
검색해보니 이미 여러 사람이 비슷한 오류를 경험한 듯 했다.
왜 IntelliJ에서는 잘 찾아지던게 Jar로 실행시키면 안되는건지 찾아보니,
Jar 파일 안의 리소스들은 file이 아닌, stream이기 때문
이라고 한다.
(기존 소스)
ClassPathResource resource = new ClassPathResource(FilePath);
String someText = new String(Files.readAllBytes(Paths.get(resource.getURI())));
(변경후)
InputStream resourceStream = getClass().getResourceAsStream("fileName")
BufferedReader br = new BufferedReader(new InputStreamReader(resourceStream));
String line;
StringBuilder someText = new StringBuilder();
while ((line = br.readLine()) != null) {
someText.append(line).append('\n');
}
참고
https://stackoverflow.com/questions/47917335/loading-files-from-resource-folder-using-java-jar
'개발 > Spring' 카테고리의 다른 글
@NotNull VS @NotEmpty VS @NotBlank 어노테이션 비교 (0) | 2022.11.23 |
---|---|
failed to instantiate com.fasterxml.jackson.datatype.jsr310.javatimemodule 에러 원인과 해결 방법 (0) | 2022.11.03 |
@Component VS @Service VS @Repository 어노테이션 차이 (0) | 2022.08.18 |
Spring Security ‘hasAnyAuthority()’ VS ‘hasAnyRole()’ (0) | 2022.04.21 |
Spring MockMvc 사용법 (0) | 2022.04.19 |
Comments