当前位置:网站首页>Getclassloader() returns null, getclassloader() gets null
Getclassloader() returns null, getclassloader() gets null
2022-06-13 05:27:00 【Get rich on the yard】
One 、 Problem description
adopt getClassLoader() Way to obtain jar Resources in the package , It's empty :
this.getClassLoader().getResources("com/xxxx/test/Start.class").hasMoreElements();
this.getClassLoader().getResourceAsStream("test.txt");
Use ClassGraph, Can be changed to package name , See if you can get :
try (ScanResult scanResult = new ClassGraph().acceptPackages("com.xxx.xxx.xxx").scan()) {
scanResult.getAllResources().forEachByteArrayIgnoringIOException((io.github.classgraph.Resource res, byte[] content) -> {
String path = res.getPath();
System.out.println(" file :" + path);
});
}
Two 、 resolvent
No access to resources , Basically, the path is wrong , perhaps ClassLoader incorrect , The other problem is jar There's something wrong with the bag ,jar The directory does not exist in the package , adopt 7zip You can see :
7z l xxxx.jar
FALSE jar Package directory :
Correct jar Package directory :
边栏推荐
- Pyqt5 controls qpixmap, qlineedit qsplitter, qcombobox
- Standard input dialog for pyqt5 qinputdialog
- 【多线程编程】Future接口获取线程执行结果数据
- Windbos run command set
- MySQL transactions and foreign keys
- Django uploads local binaries to the database filefield field
- Error: unmapped character encoding GBK
- [multithreading] thread pool core class -threadpoolexecutor
- 设置自定义dialog的正确宽高
- Case - traversing the directory (file class & recursive call)
猜你喜欢

C language learning log 12.5

File descriptorfile description

Search DFS and BFS

Database design

Information collection for network security (2)

Small project - household income and expenditure software (1)

About Evaluation Metrics

Case -- the HashSet set stores the student object and traverses

Qmessagebox in pyqt5

Chapter 18 pagination: Introduction
随机推荐
[multi thread programming] the future interface obtains thread execution result data
Pychart encountered time zone problem when connecting to MySQL timezone
Pyqt5 module
How to Algorithm Evaluation Methods
About Evaluation Metrics
C language learning log 12.5
C language learning log 12.25
动态规划-最长公共子串
metaRTC4.0稳定版发布
Case - simulated landlords (upgraded version)
MySQL main query and sub query
Case - simulated landlords (primary version)
About Evaluation Metrics
Case - the ArrayList collection stores student objects and traverses them in three ways
System performance monitoring system
Hainan University Postgraduate Entrance Examination electronic information (085400) landing experience
MySQL built-in functions
Anaconda configuring the mirror source
mongo
Detailed explanation of R language sparse matrix