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 cas开发者_运维知识库es 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.
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:
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.
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
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.
精彩评论