Maven java compile error can not access CommonClassA

Background :

  • I am developing Maven multi module project.
  • One of the module is common module needed by other all modules.
  • This module contain CommonClassA.java .
  • common module is properly compiled.
  • It is installed into maven local repository properly.
  • One of the class( Billtype.java ) in other module (EmployeeBilling) refers this class( CommonClassA.java ).
  • Maven Dependency for common module is properly specified in pom.xml of EmployeeBilling module.
  • Problem :

    While compiling EmployeeBilling module it throws

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project EmployeeBilling: Compilation failure
    [ERROR] MyWorkspaceBizEmployeeBillingsrcmainjavacomemployeeBilltype.java:[79,19] error: cannot access CommonClassA
    [ERROR] -> [Help 1]**
    

    Supporting details:

  • dependency defined in EmployeeBilling> pom.xml:

  • Other classes from common module seems accessible as no error observed

  • There are no other errors like Class not found/file not found.
  • The class CommonCLassA implements Serializable
  • Same error occurs from Eclipse as well as commond line
  • I am using M2E plugin
  • Tools :

  • jdk1.7.0_02
  • OS: Windows 7
  • Eclipse JUNO and apache-maven-3.1.0
  • Thanks in advance!


    If project builds properly using eclipse compiler then it should work with Maven.

    Few things to check if its not working with maven:

  • Manually check in repository that jar is installed properly and it contains your class file.
  • Try to build project using locally installed Maven instead of maven in eclipse.
  • Set -DskipTest=true while installing your jar, as it can cause issues at times.
  • If these steps don't work then show us your pom.


    With no more information it's hard to find the cause. But I also had this problems now and then, and there are some things which could go wrong:

  • Are you using the right JAVA version (everywhere) ?
  • ... and the right java PROVIDER ? (Oracle, IBM, OpenJDK) In my case it's often this issue , I'm sometimes bound to IBM JDK, although I try to use Oracle where I can and this sometimes breaks my build.
  • Is the right maven dependency VERSION used? If you depend on it multiple times, and all in the same (lower than root) dept of dependencies, Maven will just "choose" a version. It could be that thát version is incompatible with your code of thát particular dependency
  • Skipping tests sometimes WORKS! It has something to do with maven phases and getting stuff ready for using it elsewhere.
  • Good luck :)


    I had the same problem. Even the jar dependency has the required class files. Finally I deleted the local maven repo and restarted the build. Now it worked without any issue.

    链接地址: http://www.djcxy.com/p/15294.html

    上一篇: 如何将.Net 4.0设置为MonoDevelop(Unity 3D)中的默认框架

    下一篇: Maven java编译错误无法访问CommonClassA