我有一个包含包的模块
com.temp
它具有th服务的接口和实现-
ServiceInterface
ServiceImpl
module temp {
exports com.temp;
provides com.temp.ServiceInterface with com.temp.ServiceImpl;
}
这是我的一部分pom.xml文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class TempIT {
@Test
void tempTest() {
System.out.println("JDKModulePath:" + System.getProperty("jdk.module.path")); //LINE Y
ServiceLoader<ServiceInterface> loader = ServiceLoader.load(ServiceInterface.class);
System.out.println(loader.findFirst().get().getString());//LINE X
}
}
Y线打印:
JDKModulePath:null
java.util.NoSuchElementException: No value present
.
one whole
但是不创建额外的测试模块?
这些是实现和接口:
package com.temp;
public class ServiceImpl implements ServiceInterface {
@Override
public String getString() {
return "This is test string";
}
}
package com.temp;
public interface ServiceInterface {
public String getString();
}