Balder
Balder

Reputation: 8718

How to modify the Eclipse Run Configuration classpath?

I'm developing a project in Eclipse JDT, that has optional dependencies on OSGI - that is, it supports being used as an OSGI bundle, and if it is used as a bundle inside an OSGI environment, it will also reference some classes from OSGI.

Now I want to write JUnit test cases for both running inside OSGI and running without OSGI, included in two different test suites. The OSGI tests are run as JUnit Pulg-in Tests and the Non-OSGI tests should be run as normal JUnit Tests.

Now I have the problem, that I couldn't find any way in Eclipse to exactly specify the classpath for the JUnit Test Run Configuration and exclude the optional OSGI jars.

Is there any way to exclude jars or modify the default classpath for an Eclipse Run Configuration? If not, does anyone have a suggestion, how one should setup JUnit tests in such a case?

The only solution I was able to find is, to create a jar file from my unit tests and run the tests without OSGI from a different project with the test jar file on the classpath. But I would prefer a more elegant solution, ideally without the necessity of a second test project.

Upvotes: 2

Views: 8463

Answers (2)

Balder
Balder

Reputation: 8718

With the help of Gimbys comment, I was able to solve the problem. Although it is not possible in Eclipse to modify the default classpath generated by JDT, it is possible to entirely remove the default classpath and then add your own classpath in the classpath tab of the Runtime Configuration.

To remove the default classpath, one has to select the root entry that is named after the currently run project, and then click on the "remove" button. After that one can add all the jar files and projects that should be loaded in the classpath. The downside of this approach is, that jar files, that are normally provided by Eclipse plugins like e.g. junit.jar, must then also be selected manually (e.g. by adding it to a library folder of the project or by selecting the external jar in the plugins directory of the Eclipse installation folder).

Upvotes: 2

Absurd-Mind
Absurd-Mind

Reputation: 8004

I would suggest that you split up your project in 4 separate projects:

  • Logic: This package contains all the logic, so basically what your program/plug-in does
  • Logic.plugin: This Project resembles a Plugin-Project (OSGI-Bundle). This project contains only configurations needed for your plugin and everything dependent on osgi. It has a dependency on your Logic Project.
  • Logic.plugin.test: All the test cases for your osgi bundle. It is the normal plugin approach to split up logic and test cases
  • Logic.cli: This project contains the command line interface (or whatever your alternate application is). This also depends on the Logic project.

If your CLI project is only very small you may merge it with the Logic project.

Upvotes: 0

Related Questions