Java - ServiceLoader - Intellij cannot find implementation class files

匆匆过客 提交于 2021-01-24 12:37:32

问题


Intro

I am trying to create multiple services which fuzz the input (for testing purposes. I am using the concept of dependency injection using java.util.ServiceLoader<T> feature. I am using IntelliJ for this project.

Github Project Link: https://github.com/ghoshabhi/java-service-loader

Problem

I have created a META-INF/services directory with one file within it: htmlfuzzing.spi.HtmlFuzzer mentioning the path to my implementation class (htmlfuzzing.TagReplacer). I was trying to create a structure similar to an example on Oracle's website.

I also went ahead and marked the META-INF directory as resources by going to Project Settings > Modules :

Here's what my output directory looks like:

As you can see above, the implementation class' class files are not added to the out/ directory.

Here's my complete directory structure:

Question

I am obviously doing something wrong here, but I am not able to understand what. What is the correct way of adding or marking the META-INF directory as the resources or what is the correct way to include all the service implementation classes?

Any help or hint towards solving this is appreciated.

EDIT - 1

Added src/resource folder and placed the META-INF directory within it. But I still don't see the implementation class' class files in the out directory.

Also, one thing I have noticed is as soon as I mark any directory as resource in the project structure - it vanishes from the project view pan on the left. Anything odd there?

来源:https://stackoverflow.com/questions/52302013/java-serviceloader-intellij-cannot-find-implementation-class-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!