Eclipse (実際には IBM RAD 7) で Java EE 5 プロジェクトを WebSphere 7 で実行しています。
ワークスペース プロジェクトは次のように配置されます。
webapp <-- produces a WAR file
webappEAR <-- produces the EAR file
webappEJB <-- holds the Service and DAO classes
webappJPA <-- holds the domain/entity classes
webappTests <-- holds the JUnit tests
Service クラスの 1 つ (webappEJB プロジェクト内) で、テキスト ファイルをリソースとしてロードする必要があります。
テキストファイルをフォルダーに配置しました:
webappEAR/emailTemplates/myEmailTemplate.txt
したがって、EAR ファイルには次のように表示されます。
webappEAR.EAR
/emailTemplates/myEmailTemplate.txt
私のサービスクラスでは、これは私がそれをロードする方法です:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("emailTemplates/myEmailTemplate.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(input));
/* and so on */
問題はinput
常に null です。リソースが見つかりません。
先頭のスラッシュ ( "/emailTemplates/myEmailTemplate.txt"
) を試しましたが、それもうまくいきませんでした。
私が間違っていることはありますか?または、これを行うより良い方法はありますか?
ありがとう!
ロブ