How avoid Eclipse load test-class file in to classpath when Java app run?

天大地大妈咪最大 提交于 2020-07-20 17:08:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/47549803/how-avoid-eclipse-load-test-class-file-in-to-classpath-when-java-app-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!