user2210293
user2210293

Reputation: 141

Maven java compile error can not access CommonClassA

Background:

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:

Tools:

Thanks in advance!

Upvotes: 14

Views: 35655

Answers (5)

actan
actan

Reputation: 655

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.

Upvotes: 0

Mahmoud
Mahmoud

Reputation: 11431

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.

Upvotes: 0

AGan
AGan

Reputation: 487

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.

Upvotes: 1

Jeroen van Dijk-Jun
Jeroen van Dijk-Jun

Reputation: 1038

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

Upvotes: 4

Lokesh
Lokesh

Reputation: 7940

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.

Upvotes: 4

Related Questions