14

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!

DB5
  • 13,553
  • 7
  • 66
  • 71
user2210293
  • 141
  • 1
  • 1
  • 4
  • 1
    Maybe a silly question, but is the class `CommonClassA` `public`? – DB5 Aug 15 '13 at 07:40
  • 1
    Run compilation in debug mode with `-X` like: `mvn compile -X` for more details. Also are you sure that access modifiers for the class make it visible? – ps-aux Aug 15 '13 at 07:49
  • I suggest adding the sources of your files, as it seems a regular compile error. – sorencito Aug 15 '13 at 09:50
  • 4
    I'm having exactly the same error. Did you figure out the cause? – Lii Aug 15 '14 at 16:10

5 Answers5

4

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

Few things to check if its not working with maven:

  1. Manually check in repository that jar is installed properly and it contains your class file.
  2. Try to build project using locally installed Maven instead of maven in eclipse.
  3. 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.

Lokesh
  • 7,810
  • 6
  • 48
  • 78
3

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

Jeroen van Dijk-Jun
  • 1,028
  • 10
  • 22
  • 3
    This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/13075824) – Inian Jul 21 '16 at 12:33
  • 1
    If you say so.... Just my experience, I yesterday had THAT specific compile error, and after changing JAVA_HOME from Oracle JDK to IBM JDK I got that issue fixed. But if you say it doesn't then you probably know much better. Where is your answer btw, Inian? – Jeroen van Dijk-Jun Jul 22 '16 at 09:30
  • 1
    This worked for me. The dependency for which i got can not access was using a different JAVA version – BabaNew Jul 30 '19 at 14:29
  • 1
    This also worked for me. Java version was upgraded, had to revert to get to compile again. I would certainly say it provides a answer to the question. – prometheanSun Nov 22 '19 at 00:06
1

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.

AGan
  • 457
  • 5
  • 12
0

It looks like you are using an old version of maven-compiler-plugin (v2.3.2).

I suggest you upgrade it to 3.x. it won't magically fix your issue but it will definitely give you better / more detailed error message.

Mahmoud
  • 9,729
  • 1
  • 36
  • 47
0

here is how I solved it (might be useful to others if in same case)

check the first build error, it says a jar file which is dependent has zero byte (file size is 0). That happens previously downloading that jar file was stopped in the middle.

Just delete that jar file's whole folder in your maven local repositary and then build again. Jar file will be auto download again.

Then build will be success.

actan
  • 635
  • 2
  • 9
  • 17