jakarta-eeglassfishejbwebcontent

Access files stored in a web content folder from an EJB


I have some data files in my WebApplication which I want to read.

How can I access them from an EJB?

I tried something like this but it didn't work:

@Singleton
public class Server {

  public void loadData() {
    InputStream is =
      this.getClass().getClassLoader().
      getResourceAsStream("WebContent/WEB-INF/Data/Data.xml");
    //read from is...
  }

}

Or is there any better way to handle read-only data files? I don't want to use a database, because I never have to write into these files, and I can parse big XML files very easily.


Solution

  • After some experimenting, I finally got it working. The Problem was the wrong Path. Right is:

    InputStream is = this.getClass().getClassLoader().getResourceAsStream("../Data/Data.xml");
    

    (I don't know why)...

    InputStream is = this.getClass().getClassLoader().getResourceAsStream("classpath:Data/Data.xml");
    

    is not working for me but thanks for your help.