Let eclipse use maven to compile/weave my code

自闭症网瘾萝莉.ら 提交于 2019-12-10 10:03:35

问题


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>

回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/7184364/let-eclipse-use-maven-to-compile-weave-my-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!