OSGi/BND:如何从包生成中排除类?

发布于 2024-10-19 16:13:46 字数 255 浏览 5 评论 0原文

我有一个捆绑项目(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风挽心 2024-10-26 16:13:46

问题是 Eclipse 将 src/main/java 和 src/test/java 编译到同一个输出目录(可能是“bin”)中,而 Bnd 通过扫描bin文件夹中编译后的.class文件。

您可以按照以下步骤修复此问题:

  1. 右键单击src/test/java并选择Build Path >配置输出文件夹...

  2. 单击“特定输出文件夹”并输入目录名称,例如 bin_tests

现在 Eclipse 会将测试类编译到一个单独的文件夹中,而 Bnd 只会看到真正的类。

The problem is that Eclipse is compiling both src/main/java and src/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:

  1. Right click on src/test/java and select Build Path > Configure Output Folder...

  2. 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.

狼性发作 2024-10-26 16:13:46

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

噩梦成真你也成魔 2024-10-26 16:13:46

我假设您的测试类包含在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文