4

I am using compile time weaving with aspectj to weave in Spring's transactional code so I can use @Transactional. When i run maven compile from inside Eclipse (which uses the aspectj-maven-plugin), eclipse synchronizes to the tomcat server and all goes well.

But when Eclipse compiles (project->build automatically) it appears not to weave the spring transactional code and I get this error:

javax.persistence.TransactionRequiredException: no transaction is in progress

This is very annoying because I just want to code away and not manually call maven compile after eclipse compiles every time.

Do I need to edit the Aspect Path or inPath of the AJDT plugin? Why doesn't Eclipse just use maven to build?


I am using:

  • Eclipse WTP Indigo
  • Spring 3.0.5.Release
  • JDK7 & Tomcat 7
  • m2eclipse & AJDT plugins

These are the relevant fragments of my pom.xml:

<!-- AspectJ -->
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjtools</artifactId>
    <version>1.6.11</version>
</dependency>
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.6.11</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.aspects</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>${spring.version}</version>
    <scope>compile</scope>
</dependency>

<!-- Compile time weaving -->
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>compile</id>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <verbose>true</verbose>
                <outxml>true</outxml>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
            </configuration>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
        <!-- omitted test-compile part -->
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.11</version>
        </dependency>
    </dependencies>
</plugin>
Cojones
  • 1,906
  • 22
  • 25

2 Answers2

4

I'm going through the same issue with a project I'm working on. In short: for the tool set you're using you need to enable load-time weaving or use a prior version of Eclipse. Right now, there is a problem with the m2e Eclipse plugin and the aspectj-maven-plugin integration with recent versions of Eclipse. The worst part is that the m2e guys don't really care because they don't use AspectJ.

Here are some links to the issue:

Community
  • 1
  • 1
jonathan.cone
  • 6,592
  • 2
  • 30
  • 30
  • Thanks! this clarifies things a little, I don't like LTW because it's so slow.. It's strange that they dropped Aspect-J support since it's such a cool feature. Which eclipse/plugin versions do you recommend? – Cojones Aug 25 '11 at 03:36
  • Yeah, I couldn't agree more. I think I'm using Eclipse 3.5 and m2eclipse 0.9.x. There are instructions out there someplace to fix this for m2e 0.10.x using a custom build of Eclipse, I will post them if I can find them tomorrow. – jonathan.cone Aug 25 '11 at 03:41
  • I've worked around this by still using Eclipse 3.7 but with http://m2eclipse.sonatype.org/sites/archives/0.9.9.200909092308/. This will prevent launching maven manually from eclipse but that's OK for me since i can do this from the command line when needed (not very often). – Cojones Aug 27 '11 at 20:15
  • Does you have any more information on this problem? It is really annoying and I can not find any way to solve this. – Piotr Oct 19 '11 at 17:00
  • @Piotr: I've solved it now by upgrading everything and build with the aspectj-compiler first, so eclipse catches errors and reports them. Second in comes the e2builder that compiles/weaves and enhances my source files. The final step was to check: Window->Preferences->General->Workspace->'Refresh automatically' to tell Eclipse to reload the generated/compiled sources from disk. – Cojones Mar 19 '12 at 16:22
0

In addition to Compile Automatically you should check that the JDT weaving plug-in is enabled.

Window | Preferences; click the JDT Weaving section - verify it is currently enabled. When you first installed the plug-in it asked you if you wanted to enable this, but it could be turned off if you answered "No".Make sure this screen says JDT Weaving is enabled

cschooley
  • 586
  • 4
  • 10