I want one of my compiled classes to be added into META-INF/services
folder inside of my uber-jar. Is it something to be configured inside maven-shade-plugin
?
This is the page which requires placing the file into META-INF/services
: https://nightlies.apache.org/flink/flink-statefun-docs-release-3.2/docs/modules/embedded/#defining-an-embedded-module
This means that every JAR should contain a file org.apache.flink.statefun.sdk.spi.StatefulFunctionModule in the META_INF/services resource directory that lists all available modules that it provides.
MyClass
implements StatefulFunctionModule
, but I'm not sure if I should place it alone, or place it as org/package1/package2/MyClass.class
(assuming that its package path is org.package1.package2
)
It looks like all files inside META-INF/services
are named according to their original package path, e.g. my class would be named as org.package1.package2.MyClass
then
CodePudding user response:
META-INF/services
does not contain classes, it contains text files (named after the SPI - Service Provider Interface), which lists the class names that implement that SPI. That means you would have a file called META-INF/services/org.apache.flink.statefun.sdk.spi.StatefulFunctionModule
, and its contents is:
org.package1.package2.MyClass
or - if you have multiple implementations:
org.package1.package2.MyClass
org.package1.package2.MyOtherClass
(that is, one class name per line)
Generally, you would add this file in src/main/resources/META-INF/services
, though there might be Maven plugins that can generate them for you (I'm not sure though).
Note that if you use a modular Java project, you would (also) need to define this in module-info.java
as:
module your.modulename {
// ...
provides org.apache.flink.statefun.sdk.spi.StatefulFunctionModule
with org.package1.package2.MyClass;
}