Get Folder from Jar Resources/Classpath

I am developing a plugin that uses some text files that are stored in a folder in the resources path as show below.

--src

--resources

----rules

-------rule1.txt

-------rule2.txt

I use the line below to obtain the path of the folder. It works fine when I'm running/debugging the plugin. 

getClass().getClassLoader().getResource("rules").getPath()

When create the plugin jar and install it as a Plugin, the line above throws a null pointer exception. I tried adding the 

How can I get the path for the "rules" directory?

0
3 comments

How do you create the plugin JAR? Do you use gradle-intellij-plugin? Are the text files included into the plugin JAR?

0

I used the Build Project option and then "Prepare Plugin Module <> for Deployment. 

Yeah the files are included in the plugin jar.

0

What class is returned by `getClass()` method? Which class-loader is returned by `getClassLoader()` method?

You can also debug the code by adding debug parameters to the IDE command line (Help | Edit VM Options) and then connecting to it via 'Remote' run configuration.

0

Please sign in to leave a comment.