Dynamic Path to a File
I have a binary (testBin) in `resources` folder.
In my code, when I statically get access to it (`/Users/usernameee/MyProj/src/main/resources/testBin`), it can find the binary.
But when I want to have the dynamic path to it, by dynamic I mean as it's a plugin and other people are going to install it, I need a dynamic path to the binary, so I tried: `this.javaClass.getResource("testBin")?.toString()` but I get this error:
Error: Error: Cannot find module '/Users/usernameee/Myproj/ASWorkspace/SampleAppToTryPluginInIt/app/src/main/res/drawable/jar:file:/Users/usernameee/Projectz/Myproj/build/idea-sandbox/plugins/Myproj/lib/instrumented-MyProj-1.0.1.jar!/testBin'
How can I get the path to the file under resources that work for all the machines and users who install my plugin?
Please sign in to leave a comment.
Hi,
Try using
com.intellij.util.ResourceUtil
and pass plugin class loader, e.g.YourPluginClass.class.getClassLoader()
:It returns the content of the file; I want the path.
it's an application written in nodejs, and testBin content:
___
and then I do this:
and then:
I even used `ResourceUtil.getResource(MyRightClickAction::class.java.classLoader, ".", "testBin").path` but still returns `file:/Users/usernameee/Projectz/Myproj/build/idea-sandbox/plugins/Myproj/lib/instrumented-MyProj-1.0.1.jar!/testBin` and the same error.
This did the trick:
this::class.java.classLoader.getResource("name-of-file-in-resources-folder")