0

Recently i have been playing around with writing plugins which i then load using a ServiceLoader. In order for the ServiceLoader to find my Plugins, there has to be a text file included in my jar under META-INF/services/. The text file has to be named after the Interface the ServiceLoader is "looking for" and must include the canonical name of the implementing class(es). All of this is working absolutely fine, but there is one really annoying problem with this approach: each time the project is built, i have to manually add the /services/ folder as well the text file to the jar (using Winrar). This is extremely cumbersome during development, since i have to constantly re-built the project in order to test things, which means i also have to add the folder and the text file by hand every single time as well.

I really hope there is a way to have Java add the META-INF/services/ folder as well as the text file automatically when building the project, since this is driving me insane! :)

By the way, i am using Netbeans which (afaik) is using Ant internally to automate the build process. I guess this information could be relevant to my question.

Thanks!

thousands
  • 75
  • 3

1 Answers1

2

Right click on your "Source Package", select "New | Other"

enter image description here

From the "Categories" tree, select "Other". From the "File Types" select "Folder"

enter image description here

Name thy folder...

enter image description here

Viola :D

enter image description here

Now right click on the new folder and follow the same basic steps, but this time, use "Empty File" instead to create your text file

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • wow, thanks, that works of course! i previously tried to add META-INF as a package instead of as a folder, which didn't work because of the hyphen. i can be really stupid sometimes, luckily there's people like yourself that can help with that ;) thanks again! – thousands Nov 12 '12 at 00:34
  • I use a similar approach for our plugin API ;) – MadProgrammer Nov 12 '12 at 00:36