ウェブアプリケーション(とタペストリーも)はどこにでも展開できるため、ファイルの絶対パスを知らない/気にしません。 HttpServletRequestのgetRealPathを呼び出すと、ファイルの絶対パスを取得できます。 HttpServletRequestをの
@Inject
private HttpServletRequest request;
...
// get root folder of webapp
String root = request.getRealPath("/");
// get abs path from any relative path
String abs = root + '/' + relPath;
getRealPathは、推奨されません、代わりにServletContext.getRealPathを使用することをお勧めしますが、それはのServletContextを取得するのは簡単ではありません。
私はWebApplicationInitializer実装
public class AbstractWebApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Here we store ServletContext in some global static variable
Global.servletContext = servletContext;
....
}
ありがとう!できます。 :) – LakiGeri