我有一个 OSGI 包,它使用外部 jar 进行日志记录。
<dependency>
<groupId>Tracking-Service</groupId>
<artifactId>Tracking_Service</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
在构建期间,我有一个调用日志记录 jar 的 JUnit 测试。但是 jar 没有部署到 OSGI 框架中,我得到了 NPE。
最后我需要有日志jar,它也在
<scope>provided</scope>
<scope>test</scope>
有没有办法将日志记录 jar 也包含为模拟测试?
最佳答案
有两种可能的方法可以通过 OSGI 包获取该 jar
- 获取该 jar( bundle )的 OSGI 版本并部署它(如果使用 Karaf,请尝试搜索该功能(如果可用))Spring Repo for OSGI bundles
当且仅当您找不到第一个
- 您可以将其嵌入到您的 bundle 中,如下所示
在你的 Maven 构建插件中添加以下内容
<Embed-Dependency>jar_name</Embed-Dependency>
编辑:
如果你使用的是eclipse,你可以在你的pom文件中使用以下插件
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>jar_name</Embed-Dependency>
</instructions>
</configuration>
</plugin>
关于java - 包含用于 JUnit 测试的 OSGI jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23047196/