|JDT Classpath setup and ServiceLoader [message #1060798]
||Tue, 28 May 2013 12:55
| Benjamin Muskalla
Registered: July 2009
I'm currently struggling a bit how to best setup a JDT project for the following use-cases:
* should act as a regular Java library (running plain Java and JUnit)
* will be deployed as OSGi bundle (contains manifest, pde nature)
* provides/consumes services with Java ServiceLoader
When running classes/tests from such a project, with a default JDT setup, the classpath will contain only the /bin folder, nothing else.
In order to work with ServiceLoader, you need to provide a file in "META-INF/services/fqn.Interface" which is usually not part of the classpath. Thus, any interaction with ServiceLoader works when packaged as a .jar, but not when running classes/tests inside Eclipse.
Options I've tried out so far:
* adding META-INF as classfolder
Works to get it into the classpath but under the wrong root. ServiceLoader expects to find something in "META-INF/.." while the classfolder feature only works from META-INF/ down.
* Putting the META-INF into the src folder
Works but breaks PDE tooling as it tries to find the MANIFEST within the projects root.
* Put META-INF/MANIFEST.MF in project root, services in src package
Works as the service file is on the classpath, building the jar with Tycho properly merged both folders together. But very confusing as you now deal with two META-INF folders within the same project.
* Add project root as a folder on the classpath in launch config
Works but requires manual setup for each and every launch config. Running unit tests without a manually touching the launch config is impossible.
So essentially I need to put the the project root as-is onto the classpath when launching plain junit tests, not just the bin folder.
Anyone else out there with some ideas how to accomplish such a setup?
(Attached is a minimal project with the same setup)
(Size: 4.59KB, Downloaded 106 times)
Powered by FUDForum
. Page generated in 0.02604 seconds