简体   繁体   中英

OSGi/BND: How to exclude classes from bundle generation?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM