简体   繁体   中英

How to get path to web resource from within EJB?

This is my first post on StackOverflow, so let me know if I'm breaking any rules.

As for the question:

I have a JBOSS project divided as follows:

myproject
  -myproject-ear
  -myproject-ejb
     -mypackage
       -myQuartzClass.java
  -myproject-web
     -src
        -main
          -webapp
             -protected
                -sql
                  -mySqlQuery.sql

Thing is, I need to get the path (and then read the file) to "mySqlQuery.sql") from within the "MyQuartzClass.java". Is it possible? I know I can use FacesContext.getCurrentInstance().getExternalContext().getRealPath from within a ManagedBean, but can I use something similar from within my EJB classes?

Thanks

At least for WAR deployments, you can have a ContextListener load some information into a static field of a non-@Startup-annotated EJB. There's a code sample at https://github.com/IanDarwin/GetWebFilesInEJB.git

I have not tested it on the legacy EAR deployment; if it doesn't work there, might give some people the incentive to simplify their lives a bit :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM