Tag: serviceloader

JUnit5 Platform Launcher API – 如果没有至少一个TestEngine,则无法创建Launcher

我正在尝试升级我们的自动化测试套件的测试能力以接受JUnit5测试,并且当遵循JUnit Platform Launcher API指令时,我得到错误“无法创建没有至少一个TestEngine的启动器;考虑将引擎实现JAR添加到类路径” 。 原因是以下内容无法找到TestEngine任何实例: Iterable testEngines = ServiceLoader.load(TestEngine.class,ClassLoaderUtils.getDefaultClassLoader()); 您对如何确保ServiceLoader能够找到TestEngine实例有任何建议吗? 我已经包含org.junit.jupiter.engine ,它包含实现TestEngine ,作为必需的插件。 我试过在项目的.classpath中添加一个直接路径到jupiter.engine jar。 我已经尝试在同一个文件中创建JupiterTestEngine witihn的实例并且它已成功创建,但仍未找到服务加载程序发现的TestEngine 。 编辑(回应Sormuras的评论): 这是针对Eclipse的,你可以在这里看到代码库: http : //git.eclipse.org/c/platform/eclipse.platform.releng.git/tree/bundles/org.eclipse.test 我在mainifest中添加了以下内容: org.junit.platform.launcher, org.junit.jupiter.api;bundle-version=”5.0.0″, org.junit.platform.engine;bundle-version=”1.0.0″, org.junit.platform.commons;bundle-version=”1.0.0″, org.junit.jupiter.engine;bundle-version=”5.0.0″, org.junit.vintage.engine;bundle-version=”4.12.0″ 将此添加到.classplath: 将org.junit.jupiter.engine jar添加到lib文件夹,然后添加它以包含在二进制构建中。 (我正在寻找解决方案) 我正在尝试将Tutorial代码用于http://git.eclipse.org/c/platform/eclipse.platform.releng.git/tree/bundles/org.eclipse.test/src的编辑版本。 /org/eclipse/test/EclipseTestRunner.java删除了所有旧的junit代码。

有关serviceloader的Java 9依赖性问题

基于这种情况,我有一个关于serviceloader如何在Java 9中发生变化的问题 脚本 项目gert Class Main package gert; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { static public void test() throws JAXBException { InputStream is = new ByteArrayInputStream(“”.getBytes(StandardCharsets.UTF_8)); JAXBContext jaxbContext = JAXBContext.newInstance(ClassesDef.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.unmarshal(is); } } Project gert Class ClassesDef package gert; import javax.xml.bind.annotation.XmlAttribute; […]

如何使java ServiceLoader在NetBeans 6.9模块应用程序中工作

我在NetBeans模块应用程序中使用java ServiceLoader时遇到了麻烦。 这是我正在尝试做的(它在Eclipse中的普通java应用程序中工作): 我有一个interface.jar,它声明了接口。 我有implements.jar,它有几个这个接口的实现,都在spi / META-INF / services / my.package.name.MyInteface文件中指定(这个文件位于implementation.jar中)。 我还有一个类ImplementationHandler(在另一个handler.jar中),它有以下方法来加载所有实现: private static List<MyInterface> loadAllImplementations() { List<MyInterface> foundImplementations = Lists.newArrayList(); try { for (MyInterface implementation : ServiceLoader.load(MyInterface.class)) { foundImplementations.add(implementation); } } catch (ServiceConfigurationError error) { system.out.println(“Exception happened”); } return foundImplementations; } 此代码返回Eclipse正常应用程序中的所有实现(foundImplementations.size()> 0)。 但是在NetBeans下,它找不到任何内容(foundImplementations.size()== 0)。 更多细节: 我有一个NetBeans模块应用程序的源代码(开源,不是我编写的),我需要通过使用一些MyInterface实现来扩展它。 interface.jar,implements.jar和handler.jar是在Eclipse中创建的,它们是另一个应用程序的一部分。 在NetBeans中,我打开了需要使用新function的模块,我将所有3个jars添加为外部库(NetBeans将它们复制到其ext文件夹中,我不想要但我无法做任何事情 – 我想要他们在另一个myext文件夹中,但这是另一个故事)。 然后我重新构建了所有内容并尝试使用我的一个实现,但是没有找到…获得实现的代码在ImplementationHandler类中,看起来像: public static […]

Java SPI – ServiceLoader – 将多个JAR添加到APP类路径

我在项目中实现此逻辑时遇到问题。 我使用ServiceLoader,我不知道,或者它是否可能,但我想动态地将JAR添加到app的某个已知目录,因此应用程序可以在启动时加载它们。 我唯一获得的是我知道如何创建可扩展的ONE JAR(使用META-INF / services),因此我可以为此JAR添加越来越多的提供者和类(实现)。 JAR包含在类路径中,就像普通的库一样,所以app知道它。 我想要实现的目标:我不想扩展一个jar文件,但我希望通过添加更多的jar来扩展app,例如插件与提供者(服务),但我不知道如何。 感谢帮助!

何时使用ServiceLoader而不是像OSGi这样的东西

作为对依赖性过敏的人,我何时会使用像OSGi而不是内置的java 6 http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html (我想要的)让插件jar子掉进去)。 (仅供参考,这是一个scala应用程序,对任何建议开放,ServiceLoader非常接近我想要的)。

如何在java中覆盖服务提供者

这是一个更普遍的问题示例:我正在使用xstream和woodstox,woodstox附带了一个服务提供者,用于注册com.ctc.wstx.stax.WstxOutputFactory的woodstox jar中的javax.xml.stream.XMLOutputFactory。 我想提供自己的javax.xml.stream.XMLOutputFactory,并且在类路径中仍然有woodstox jar。 我知道我可以提供我自己的系统属性javax.xml.stream.XMLOutputFactory,但是我正试图从我们的开发团队中解脱麻烦并使用我的jar中的服务文件或者在我的战争中使用META -INF / services文件夹。 查看javax.xml.stream.FactoryFinder的代码如何确保我的META-INF / services / javax.xml.stream.XMLOutputFactory文件将是FactoryFinder使用的文件? 我们将xstream与camel一起使用,并且无法找到将工厂注入XStreamDataFormat的方法