15

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?

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

posting your pom.xml file and you src tree would help (linux tree command)
I had the same problem after some compile issues upstream during a full mvn clean install. The problem was Eclipse resolves from its own workspace but maven had to work with an incomplete or faulty local repository. Solution: perform a mvn clean install on the full project again (from the command line), which according to m2eclipse will yield no more compile errors upstream
1

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.

Comments

-3

add to pom.xml:

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> <compilerArguments> <extdirs>src\main\webapp\WEB-INF\lib</extdirs> </compilerArguments> </configuration> </plugin> </plugins> </build> 

1 Comment

Why do you think, this would help?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.