I really did a lot of research before asking this, it seems like I'm missing something. I try to implement a ServiceLoader and therefore made an example class:
the code is simple:
testInterface.java
package com.test;
public interface testInterface {
void test();
}
testImpl.java
package com.test;
public class testImpl implements testInterface {
@Override
public void test() {
System.out.println("test");
}
}
Main.java
package com.test;
import java.util.ServiceLoader;
public class Main {
public static void main(String[] args) {
ServiceLoader<testInterface> serviceLoader = ServiceLoader.load(testInterface.class);
serviceLoader.iterator().next().test();
}
}
com.test.testInterface
com.test.testImpl
I keep getting a NoSuchElementException at the iterator part which means that the implementation was not loaded. Thanks in advance.
Put your META-INF/services/ into resources/ and add it to the Eclipse project as a source folder. It will be automatically included in the JAR file when you compile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With