Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant import src/main/java classes into src/test/java jUnit tests in maven-spring-web project. IDE - Eclipse

I'm working on a maven-spring-web project in Eclipse. I am getting some problem working with jUnit tests, it seems to me a configuration issue.

Project structure:

src > main > java : business logic goes here
src > test > java : jUnit test cases are parked here.

The trouble is that imports are not working when im trying to import some business logic classes from src>main>java into my jUnit test cases. The reason is that the physical folder structure is :

Business logic classes : project_root > src > main > java Test cases classes : project_root > src > test > java

I've tried cleaning, putting testResources directory in POM. I dont want to add classes folder in classpath. Pls advise.

like image 905
Harsh Dadhich Avatar asked Mar 06 '26 14:03

Harsh Dadhich


1 Answers

You can't use default package in src/main/java, try to new a package and you can import the class then.

like image 53
Zhengang Wei Avatar answered Mar 08 '26 02:03

Zhengang Wei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!