'Cant find file path in JAR file

The code below works when the frontend and backen are appart , not a jar file. Am I missing something?

   @RequestMapping(value = "/getPdf/{userType}/{userRoll}/{trainingFileName}", method = RequestMethod.GET)
        public ResponseEntity<InputStreamResource> getPdf(@PathVariable("userType") String userType,
                                                          @PathVariable("userRoll") String userRoll,
                                                          @PathVariable("trainingFileName") String trainingFileName) throws FileNotFoundException {
    
           String fileName =trainingFileName + ".pdf";
            String filePath = "TrainingDocuments\\SuperUser\\2\\PartnerInformation\\PartnerInformation.pdf";
    
          //TrainingDocuments\SuperUser\2\PartnerInformation\PartnerInformation.pdf
    
            File file = new File(filePath);
            HttpHeaders headers = new HttpHeaders();
            headers.add("content-disposition", "inline;filename=" +fileName);
    
            InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
            return ResponseEntity.ok()
                    .headers(headers)
                    .contentLength(file.length())
                    .contentType(MediaType.parseMediaType("application/pdf"))
                    .body(resource);

    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source