簡體   English   中英

如何在Web應用程序中為jar接收正確的類加載器?

[英]How to receive correct class loader for jar in web application?

我有應用程序mywebapp。 此應用程序取決於myjarconfig.jar。 文件myjarconfig.jar包含文件config.xml。 要獲取資源,我使用代碼:

InputStream confStream = ClassLoader.class.getResourceAsStream("/conf/config.xml");

但是我總是收到null。 當我查看調試器時-我看到ClassLoader是mywebapp。 為什么不是jar文件? 需要檢查什么? 謝謝。

如果您的jar位於WEB-INF / lib,容器的類路徑,引導類路徑等位置,則應使用

Thread.currentThread().getContextClassLoader().getResourceAsStream("/conf/config.xml")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM