开发者

Let eclipse use maven to compile/weave my code

开发者 https://www.devze.com 2023-03-30 07:11 出处:网络
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), e

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>
                    开发者_如何学Python<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>


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:

  • A similar issue
  • A mailing list entry describing the issue
  • A bug entry for this issue
  • An external project started to resolve the issue which appears to have stalled out


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".

Let eclipse use maven to compile/weave my code

0

精彩评论

暂无评论...
验证码 换一张
取 消