0

I'm trying to access xsd in resource folder for eg. resource/xyz/abc/data.xsd in spring boot application using below code,

@Autowired
private ResourceLoader resourceLoader;

...

final Resource fileResource = resourceLoader.getResource("classpath:XYZ/view/abc.xsd");

fileResource.getFile()

Which runs or access xsd file in resource folder properly when I run the application locally same is not happening for test environment which is in cloud Does anyone has any idea what would be the reason.

Thanks in advance

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
tyro
  • 765
  • 2
  • 13
  • 34
  • Possible duplicate of [How to get files from resources folder. Spring Framework](http://stackoverflow.com/questions/36407575/how-to-get-files-from-resources-folder-spring-framework) – Kh.Taheri May 19 '17 at 10:05
  • To me it should not be the same as whatever code is written is working properly on local machine but same is not working for test environment which is in cloud – tyro May 19 '17 at 10:31
  • Because it isn't a file anymore. When running locally you are probably running the main boot app from your IDE. Which makes the file accessible as file (as it isn't packaged as a jar). When packaged as a jar it cannot be retrieved as a `File` anymore you can only read it with an `InputStream`. The same will happen locally if you run with `java -jar your-app.jar`. – M. Deinum May 19 '17 at 10:38
  • The link mentioned has exact solution for the question, https://stackoverflow.com/questions/9280226/referencing-a-xsd-schema-within-jar-file – tyro May 23 '17 at 08:46

0 Answers0