Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven "class file for ... not found" compilation error

I have a Maven project. When I try to build it with Maven, I get this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
  3.2:compile (default-compile) on project myProject: Compilation failure:
  Compilation failure:
[ERROR] ClassA.java:[32,38] cannot access ClassB
[ERROR] class file for ClassB not found

ClassB is inside another artifact, and that artifact is in the local repository. In fact, I have no problems building this project with the m2eclipse Maven plugin. It's only when I run mvn compile that the build fails.

What do I have to do to build from the command line?

like image 957
ade Avatar asked Mar 13 '12 23:03

ade


People also ask

What is compilation in Maven?

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax. tools. JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.


2 Answers

Eclipse might be bypassing your pom dependencies and 'helping' you by finding a dependency that is not in your pom. Then when you run from command line eclipse isn't there to help anymore. I would double check your pom that you explicitly state dependency. You can also try

mvn dependency:analyze

for more info.

like image 172
cyber-monk Avatar answered Oct 29 '22 19:10

cyber-monk


That looks like you have defined a usual class within the src/test/java instead of the src/main/java area which is sometimes the problem cause the eclipse things behaves a little bit different.

like image 1
khmarbaise Avatar answered Oct 29 '22 19:10

khmarbaise