How to read a file that is inside an EAR

Asked

Viewed 74 times

0

I have the following structure of an Ear application

  • myApplication.Air
    • /META-INF/file.properties
    • War/WEB-INF/lib/myLib.jar/myClasse.java file

I would like to retrieve the file from my Classe.java.

I’ve tried to:

getClass(). getResource("/META-INF/file.properties") getClass(). getClassLoader(). getResource("/META-INF/file.properties") Classloader.getSystemClassLoader(). getResource("/META-INF/file.properties")

All return null

Does anyone have any suggestions?

1 answer

0

Try this way:

URL url = SomeClassInEar.getClass().getClassLoader().getResource("/META-INF/arquivo.properties");
File file = new File(url.getPath());
FileInputStream fis = new FileInputStream(file);

I hope I’ve helped

  • So, I have no class directly in the EAR. The class is within a lib within the War that is within the EAR. This solution of yours corresponds to my second example that didn’t work. The returned url is null. But thanks anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.