6

I am using STS to develop a large Spring Boot based application. We have multiple maven projects and a parent project to include them all. Each project has own testing code and config files.

When I run the Spring Boot application in the main entry class. The test-classes folder of the depended projects will be loaded into the app running classpath, that causes some conflict of spring bean definition. I have to config every project removing [src/test/java and src/test/resources] from the 'source folders on build path'.

The whole project structure is like below:

app-parent

sub-app-1

sub-app-2

sub-app-3

main-app [running from this project]

main-app project has dependencies on the sub-app-1 ~ 3.

Is there any way to let STS (Eclipse) run a Java App excluding the test-classes folder from classpath? I really do want the testing code under source folder but not have them when the App run.

Besides, I tried open the [run configuration], but it can only add more file to the classpath.

enter image description here

Community
  • 1
  • 1
Chris
  • 6,431
  • 10
  • 44
  • 59
  • 3
    Right at the bottom of the dialog you show in your screenshot, there's a checkbox called "Exclude test code". When ticked, your test classes should be ommitted from the classpath. – Torsten Crass Feb 05 '19 at 08:36

1 Answers1

7

As pointed out by @torsten-crass, verify that Exclude test code is ticked in your Classpath tab of Run configurations in Eclipse.

Here is the screenshot.

enter image description here

divinedragon
  • 5,105
  • 13
  • 50
  • 97
  • somehow all my boot launch configs did have that unchecked. is this not the default or are just my eclipse settings screwed up? – elonderin Jul 16 '20 at 14:33
  • @elonderin not sure. I started to face this when I recently updated my Eclipse. – divinedragon Jul 16 '20 at 18:19
  • 1
    @elonderin: It's not the default, but in my view it _should be_: if I run a program which is neither a JUnit test nor even located in the `src/test/java` folder, I should expect that data from under `target/test-classes` are _inaccessible to the ClassLoader_ - unless explicity stated otherwise. I've been surprised to find that Eclipse behaves differently. – Tillmann Jun 23 '21 at 09:30