简体   繁体   中英

Classloader Resource - Null value

I am using below code to print/access the root resource location in test cases: this.getClass().getClassLoader().getResource(".")

However, this yields different results when I run the test cases using Maven or ANT. For Maven build, I get the correct path "C:\\....", but ANT returns null here.

Any idea what am I missing here?

UPDATE: Project structure - src/resources | tst/resources.

Maven and Ant uses different class loader systems. Maven uses the Classworlds framework

Maven uses the Classworlds classloading framework with which we create our classloader graph.

Whereas Ant uses the "Java's delegation model"

Ant's class loader implementation uses Java's delegation model

Your result may then differ because the ClassLoader on which your are calling getResource(".") is not the same between Maven and Ant. The results you will yield is highly dependent on the ClassLoader implementation.

似乎在2.5之前的ANT版本中存在一个错误,该错误导致ANT既不复制tst / resources也不将它们添加到class-path( JIRA#IO-451 )。

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