java.io.FileNotFoundException: class path resource [] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/Users/msi/Desktop/spring-boot-tapcell-aws-exe.jar!/BOOT-INF/classes!/
In the spring boot Application Run It works fine. But After creating jar file when I run this it shows file not found exception
@Component public class FileUploadHealper {
public final String UPLOAD_DIR = new ClassPathResource("/static/").getFile().getAbsolutePath();
//new ClassPathResource("static").getFile().getAbsolutePath();
public FileUploadHealper( ) throws IOException{
}
@Getter
@Setter
private long currDatefile;
public Boolean uploadProFile(MultipartFile multipartFile,String roll) {
initFewDirectory();
createStudentRollDirectory(roll);
Date date = new Date();
long currDate = date.getTime();
boolean f=false;
try {
System.out.println("hello sir");
Files.copy(multipartFile.getInputStream(),Paths.get(UPLOAD_DIR+"/image/students/"+roll+"/"+File.separator+String.valueOf(currDate)+multipartFile.getOriginalFilename()) , StandardCopyOption.REPLACE_EXISTING);
f=true;
setCurrDatefile(currDate);
System.out.println(new ClassPathResource("/static/image/").getFile().getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
return f;
}
public Boolean uploadNotice(MultipartFile multipartFile) {
initFewDirectory();
Date date = new Date();
long currDate = date.getTime();
boolean f=false;
try {
Files.copy(multipartFile.getInputStream(),Paths.get(UPLOAD_DIR+"/image/notice/"+File.separator+String.valueOf(currDate)+multipartFile.getOriginalFilename()) , StandardCopyOption.REPLACE_EXISTING);
f=true;
setCurrDatefile(currDate);
System.out.println(new ClassPathResource("/static/image/notice/").getFile().getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}
return f;
}
private void createStudentRollDirectory(String roll) {
String path = UPLOAD_DIR+"/students/"+roll;
File pathAsFile = new File(path);
if (!Files.exists(Paths.get(path))) {
System.out.println("success");
pathAsFile.mkdir();
}
}
public void initFewDirectory() {
System.out.println("this is test");
String staticpathString = null;
try {
staticpathString = new ClassPathResource("/static/").getFile().getAbsolutePath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String path[] = {staticpathString,UPLOAD_DIR,UPLOAD_DIR +"/students/",UPLOAD_DIR+"/notice/"};
for(String x : path) {
File pathAsFile = new File(x);
if (!Files.exists(Paths.get(x))) {
System.out.println("success");
pathAsFile.mkdir();
}
}
}
}