Maven compile gives: Cannot find symbol - For a class sitting in the same app

后端 未结 3 1197
耶瑟儿~
耶瑟儿~ 2021-02-20 14:13

It\'s a while since I met such puzzling issue. I\'m having a class that references another one sitting in another package in the same application, that is, NOT in another jar ar

相关标签:
3条回答
  • 2021-02-20 14:23

    try to add below line in pom.xml which i feel it is missing

     <profile>
          <id>acceptance</id>
          <activation>
            <activeByDefault>false</activeByDefault>
          </activation>
          <properties>
          <test.source.dir>src/test/java/com/thalasoft/learnintouch/rest/config</test.source.dir>
          </properties>
        </profile>
    
    0 讨论(0)
  • 2021-02-20 14:35

    Problem Description:

    I had similar problem with my project with below structure.

    project
    -pom.xml
    
    -common-module  
    --src, pom.xml, etc
    
    -web-module  
    --src, pom.xml, etc (but dependent on 'common')
    

    mvn install would run fine for common-module but gives compilation error for web-module code that uses java class from common-module (cannot find symbol). I was using JDK 8 + Maven 3.2.5, but in pom compiler lever is set to 7.

    MY Solution:

    I have installed JDK 7 and Maven 3.1.1 and did a mvn install. Bingo..! Every with worked fine & Build Successful.

    I couldn't find a solution for my problem any where, so though of posting my fix here as it is related. (may be it could help some one)

    0 讨论(0)
  • 2021-02-20 14:43

    With maven your tests can access to all the source code of your project (src/main/java) and all the test source code (default is src/test/java).

    Here, your profile rest defines the test source directory as src/test/java/com/thalasoft/learnintouch/rest So, your test code can access everything in src/main/java and everything in src/test/java/com/thalasoft/learnintouch/rest

    Your profile acceptance defines the test source directory as src/test/java/com/thalasoft/learnintouch/rest/acceptance So, your test code can access everything in src/main/java and everything in src/test/java/com/thalasoft/learnintouch/rest/acceptance. WebTestConfiguration is not accessible since it's in a package above.

    To run specific tests with different profiles, I recommend to configure the surefire plugin in charge of running tests. A good example is available here : https://weblogs.java.net/blog/carcassi/archive/2011/04/21/running-integration-tests-and-unit-tests-separately-maven

    0 讨论(0)
提交回复
热议问题