OSGi/BND:如何从包生成中排除类?
我有一个捆绑项目(Eclipse),其结构如下:
<代码>src/main/java 在这里捆绑源文件 src/测试/java 捆绑内部测试用例
当我尝试制作捆绑包时,出现错误,指出存在一些“未解决的引用”。该错误是由内部测试类引起的。如何配置 BND 以忽略这些类?
将测试用例拆分为单独的项目并不是一种选择,因为测试用例的粒度比捆绑包提供的 API 更细。
I have a bundle project (Eclipse) that has the following structure:
src/main/java Bundle source files here src/test/java Bundle internal test cases
When I try to make the bundle I get an error that there are some "Unsolved references". The error is causes by the internal test classes. How do I configure BND to ignore those classes?
Splitting the test cases into a separate project is not an option as the test cases are of a much finer granularity as the API provided by the bundle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是 Eclipse 将 src/main/java 和 src/test/java 编译到同一个输出目录(可能是“bin”)中,而 Bnd 通过扫描bin文件夹中编译后的.class文件。
您可以按照以下步骤修复此问题:
右键单击
src/test/java
并选择Build Path >配置输出文件夹...单击“特定输出文件夹”并输入目录名称,例如
bin_tests
。现在 Eclipse 会将测试类编译到一个单独的文件夹中,而 Bnd 只会看到真正的类。
The problem is that Eclipse is compiling both
src/main/java
andsrc/test/java
into the same output directory, probably "bin", and Bnd works by scanning the compiled .class files in the bin folder.You can fix this by following these steps:
Right click on
src/test/java
and select Build Path > Configure Output Folder...Click "specific output folder" and enter a directory name such as
bin_tests
.Now Eclipse will compile the test classes into a separate folder, and Bnd will only see the real classes.
OSGi 中单元测试的好方法是使用片段。因此,您可以将测试放在片段包中,这样就不会再遇到此问题了。此外,测试将可以访问所有类,而不仅仅是 API,如果您将它们放在一个简单的包中,情况就会如此
The good approach for unit tests in OSGi is to use fragments. Therefore you could put your tests in a fragment bundle, and you wouldn't have this issue anymore. And moreover, the tests will have access to all the classes and not only to APIs as it would be the case if you put them in a simple bundle
我假设您的测试类包含在 jar 包文件中(实际情况不应该如此)。检查 jar 文件的内容并修改打包过程以不包含测试类(maven 构建不包含
src/test/java
)。当我使用 m2eclipse 打包我的项目时,有时会注意到这种行为,而从命令行运行 Maven 效果很好。
I assume that your test classes are included in the jar bundle file (what should not be the case). Check the content of your jar file and modify the package process to not include the test classes (a maven build does not include
src/test/java
).I sometimes noticed this behaviour when using m2eclipse to package my project whereas running maven from the command line worked well.