(no such file or directory) getClass().getResource(

Java

12/01/2018

Olá,

Tenho um projeto Web em Maven.
Quando starto o Tomcat no Eclipse e acesso no navegador, o sistema funciona normalmente. Quando eu gero o .war e faço o deploy no servidor, ele não consegue carregar esse arquivo, erro "no such file or directory".
Já até conferi no servidor se o arquivo estava no caminho correto depois do deploy, e estava sim.

Alguém pode me auxiliar?

(no such file or directory)
getClass().getResource("/redes/file.zip").getFile();
Wellington Oliveira

Wellington Oliveira

Curtidas 0

Respostas

Wellington Oliveira

Wellington Oliveira

12/01/2018

I made a change on my code and now it works fine:

i changed this:

		File file = new File(getClass().getResource(caminhoRede).getFile());

to this:

		InputStream in = getClass().getResourceAsStream(caminhoRede);
		File file = File.createTempFile("stream2file", ".tmp");
		file.deleteOnExit();
        try (FileOutputStream out = new FileOutputStream(file)) {
            IOUtils.copy(in, out);
        }



GOSTEI 0
POSTAR