tags:

views:

236

answers:

4

I have the following snippet in my pom.xml (Full pom attached below which can be executed)

<dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.5.3</version>
</dependency>

and in one of my Java files I refer a class org.aspectj.lang.ProceedingJoinPoint. When I do a "mvn clean install" it compiles and builds fine but when I do an eclipse:eclipse, and import the project in eclipse it gives me an error The import org.aspectj cannot be resolved. I checked the .classpath file that was generated and it does not have an entry to this file. I tried a "mvn dependency:tree" and it lists this fine.

I don't have any fancy settings for not compiling any java files. It is just a routine pom which puzzles me.

Can someone tell me what is going wrong here?

UPDATE 1: I am using maven eclipse plugin Version: 2.7

UPDATE 2: Just use pom below and do a mvn eclipse:clean eclipse:eclipse from the command line

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ekanathk</groupId>
    <artifactId>stackoverflow</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.5.3</version>
        </dependency>
    </dependencies>
</project>
+4  A: 

I just tried to reproduce the problem and... couldn't. This is the .classpath I get after adding the aspectj:aspectjrt:jar:1.5.3 dependency to a freshly created project:

<classpath>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="var" path="M2_REPO/aspectj/aspectjrt/1.5.3/aspectjrt-1.5.3.jar">
    <attributes>
      <attribute value="jar:file:/home/pascal/.m2/repository/aspectj/aspectjrt/1.5.3/aspectjrt-1.5.3-javadoc.jar!/" name="javadoc_location"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

What version of the maven eclipse plugin are you using? Did you configure it to use AJDT? Can you show your configuration?

Pascal Thivent
Using Maven eclipse plugin 2.7. How do I configure it to use AJDT? Plus, shouldn't it work with Zero config. aspectj is just another library like say log4j ?
Calm Storm
Just adding a dependency to the classpath is zero config (once in the pom), as shown above. However, the eclipse plugin can't guess if you are using AJDT or not so you have to tell him (http://maven.apache.org/plugins/maven-eclipse-plugin/examples/ajdt-projects.html). But this doesn't solve the weird class path problem. BTW, I suggest using version 2.8.
Pascal Thivent
Just using the Maven eclipse plugin 2.8 solves the problem. I just hate systems trying to be "over-intelligent" than what they are supposed to be. In this case I was inspecting some code and wanted to get in eclipse ASAP but things like these are a pain in the ***.
Calm Storm
A: 

I had similar problem. Running mvn eclipse:clean and then mvn eclipse:eclipse helped.

koppernickus
I have tried this already and this does not help
Calm Storm
+1  A: 

I've had similar problem. Eclipse plugin for maven assumes Eclipse has its own support for AspectJ. So you need to tell it you have none (or tell it which version you have). Adding

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <configuration>
        <ajdtVersion>none</ajdtVersion>
    </configuration>
</plugin> 

to <build> <plugins> section should help.

Tadeusz Kopec
A: 

Have you tried using m2eclipse instead? It tends to produce much better results in my experience.

Dominic Mitchell