I have a project (Spring) that runs perfectly and runs under Eclipc. All files are located. Technically they are in src / main / resources. I read for example the file in the code like this:
private final String KEY_FILE = "AccessKey.key"; private void setKey() { ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {}); Resource resource = appContext.getResource(KEY_FILE); ((ClassPathXmlApplicationContext) appContext).close(); // работали ради этого serverKey = readFile(resource); } private String readFile (Resource resource) { StringBuilder sb = new StringBuilder(); BufferedReader br = null; String line; try { br = new BufferedReader(new InputStreamReader(resource.getInputStream(), "UTF-8")); while ((line = br.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } finally {if(br != null) try { br.close(); } catch (IOException e) { e.printStackTrace(); }} return sb.toString(); } after exporting the project to jar, the launch leads to the error:
java.io.FileNotFoundException: class path resource [AccessKey.key] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) I suspect when compiling is not set to pass the ClassPath to the jar. tell me where to look.