getResource() only indexing compile output folder

Answered

I'm on Ubuntu 22.04. I have been trying to debug why getClass().getResource() was not finding my file, and after printing the getResource file path that it is indexing, it is only searching through the compile output folder. Even when I use "../" multiple times to escape the folder, it then returns only null.

Resulting in:

I've tried specifying the resources folder. I've also tried using a completely new compile output folder (hence folder named "GOAWAY") and it still only looks that folder. The compile output is also excluded in Intellij.

It has recently started showing the orange exclude folder but not showing is excluded on the side. Clicking "Excluded" on the top doesn't change anything either.

Here is the file path showing null after trying to escape the "blockchain" folder in the file path /home/polyphery/Desktop/Fall2022/Honours/post-quantum-blockchain/blockchain/out/production/blockchain/

Now the file path is null.

I don't really know how to continue. Please let me know if anyone has any tips at all!

0
4 comments

Hi - could you please upload your project privately to https://uploads.jetbrains.com and provide the upload id here? I'll take a look.

1

Hi Arina,

Just reuploading my project, the new id is: 2022_10_08_ph6Ev8CxF5MsvKnHxijm2g (file: blockchain.zip)

I realized it was missing some required libraries in order to run so it should be good now! Thank you!

0
Thank you, checking.
0
Hi, Looks like getClass().getResource(path) is *supposed* to load resources from the classpath, and not from a filesystem path. See https://stackoverflow.com/questions/2343187/loading-resources-using-getclass-getresource
0

Please sign in to leave a comment.