Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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] \MyWorkspace\Biz\EmployeeBilling\src\main\java\com\employee\Billtype.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!

like image 494
user2210293 Avatar asked Aug 15 '13 03:08

user2210293


1 Answers

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 :)

like image 90
Jeroen van Dijk-Jun Avatar answered Sep 28 '22 04:09

Jeroen van Dijk-Jun