webjars / webjars-play

MIT License
80 stars 34 forks source link

About initialization of WebJarAssetLocator #98

Closed Saisse closed 3 years ago

Saisse commented 3 years ago

After updating webjar-play to 2.8.0-1, WebJarUtil # locate () now throws a NotFoundException, so I've been digging around and found the commit below.

https://github.com/webjars/webjars-play/commit/b5dc83fd6e29bb6d82cf79c79a63990bb64fdbbb#diff-b98ad7af20fe7608ecc9194507aeaa2999edda4b474d2de58628130f98a7ea68

In my application environment.classLoader == Thread.currentThread (). getContextClassLoader is false, so webJarAssetLocator is initialized using environment.classLoader.

I couldn't reproduce the problem with test-project, so I used test-project to test if the webJarAssetLocator initialized with environment.classLoader works.

https://github.com/Saisse/webjars-play/tree/environment.classLoader

Neither OpenJDK8 nor OpenJDK11 works.

JDK version test openjdk version "1.8.0_292"-> NotFound openjdk version "11.0.11" 2021-04-20-> NotFound

Reverting webjars-locator to 0.37 works, but later versions do not.

webjars-locator versions Test 0.40-> Not Found 0.39-> Not Found 0.38-> Not Found 0.37-> Succeed

In addition, environment.classLoader (buildLoader) cannot access resources without the parent class loader.

https://github.com/playframework/playframework/blob/53e55f017f508f0dcdf2a70327bd73153fe87e5e/dev-mode/run-support/src/main/scala/play/runsupport/Reloader.scala#L219-L255

This commit of webjars-locator-core has excluded the parent class loader from scanning since 0.40. This is also consistent with the test results https://github.com/webjars/webjars-locator-core/commit/12a962be3e2e35f8343d97f71ddea932d1ab8dff

I think the code that initializes webJarAssetLocator with environment.classLoader should be removed, is that correct?

jamesward commented 3 years ago

Thanks for digging in. That makes sense. I'm releasing 2.8.8 shortly which hopefully will fix this.