Java Maven Compilation Error Cannot Access CommonClassA

Background

  • I am developing a Maven multi module project.
  • One of the modules is a common module, necessary for all other modules.
  • This module contains CommonClassA.java .
  • The common module is compiled correctly.
  • It is correctly installed in the local maven repository.
  • One of the classes ( Billtype.java ) in another module (EmployeeBilling) belongs to this class ( CommonClassA.java ).
  • The Maven dependency for the common module is correctly specified in the pom.xml of the EmployeeBilling module.

Problem :

When compiling the 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]** 

Supported details:

  • dependency defined in EmployeeBilling> pom.xml:

  • Other classes from the common module seem to be accessible, since no errors are observed

  • Other errors, such as Class not found / file, were not found.
  • CommonCLassA class implements Serializable
  • The same error occurs from Eclipse, as well as for commond line
  • I am using the M2E plugin

Tools

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

Thanks in advance!

+7
maven compiler-errors multi-module
source share
3 answers

If the project is built correctly using the eclipse compiler, it should work with Maven.

A few things to check if maven doesn't work:

  • Manually check the repository that the jar is installed correctly and it contains your class file.
  • Try building a project using a locally installed Maven instead of maven in eclipse.
  • Set -DskipTest = true when installing the jar, as this can cause problems at times.

If these steps do not work, show us your pom.

+3
source share

Without additional information, it is difficult to find a reason. But I also had these problems from time to time, and there are some things that may go wrong:

  • Are you using the correct version of JAVA (everywhere)?
  • ... and the right java PROVIDER ? (Oracle, IBM, OpenJDK) In my case , this is often a problem , I am sometimes tied to the IBM JDK, although I try to use Oracle wherever I can, and this sometimes breaks my build.
  • Is the correct maven VERSION dependency dependency used? If you depend on it several times and all in one (lower than root) dependency level, Maven will simply β€œchoose” the version. This version may not be compatible with your specific dependency code.
  • Skipping tests sometimes WORKS! This has something to do with the maven phases and the readiness for use elsewhere.

Good luck :)

0
source share

I had the same problem. Even jar dependency has the necessary class files. Finally, I deleted the local maven repository and restarted the build. Now it worked without any problems.

0
source share

All Articles