【问题标题】:Let eclipse use maven to compile/weave my code让eclipse使用maven编译/编织我的代码
【发布时间】:2011-11-03 07:17:44
【问题描述】:

我正在使用带有 aspectj 的编译时编织来编织 Spring 的事务代码,因此我可以使用 @Transactional。当我从 Eclipse(它使用 aspectj-maven-plugin)内部运行 maven compile 时,eclipse 会同步到 tomcat 服务器并且一切顺利。

但是当 Eclipse 编译(项目->自动构建)时,它似乎没有编织 spring 事务代码,我得到了这个错误:

javax.persistence.TransactionRequiredException: no transaction is in progress

这很烦人,因为我只想编写代码而不是在每次 eclipse 编译后手动调用 maven compile。

我需要编辑 AJDT 插件的 Aspect Path 或 inPath 吗?为什么 Eclipse 不直接使用 maven 构建?


我正在使用:

  • Eclipse WTP 靛蓝
  • Spring 3.0.5.Release
  • JDK7 & Tomcat 7
  • m2eclipse & AJDT 插件

这些是我的 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>

【问题讨论】:

    标签: eclipse spring tomcat aspectj compile-time-weaving


    【解决方案1】:

    我正在处理的一个项目也遇到了同样的问题。简而言之:对于您正在使用的工具集,您需要启用加载时编织或使用早期版本的 Eclipse。现在,m2e Eclipse 插件和 aspectj-maven-plugin 与最新版本的 Eclipse 集成存在问题。最糟糕的是,m2e 的人并不真正关心,因为他们不使用 AspectJ。

    以下是该问题的一些链接:

    【讨论】:

    • 谢谢!这澄清了一点,我不喜欢 LTW,因为它太慢了。奇怪的是,他们放弃了 Aspect-J 支持,因为它是如此酷的特性。您推荐哪些 eclipse/插件版本?
    • 是的,我完全同意。我想我正在使用 Eclipse 3.5 和 m2eclipse 0.9.x。有使用 Eclipse 的自定义版本为 m2e 0.10.x 修复此问题的说明,如果我明天能找到它们,我会发布它们。
    • 我已经通过仍然使用 Eclipse 3.7 但使用 m2eclipse.sonatype.org/sites/archives/0.9.9.200909092308 来解决这个问题。这将防止从 Eclipse 手动启动 maven,但这对我来说没问题,因为我可以在需要时从命令行执行此操作(不经常)。
    • 你有关于这个问题的更多信息吗?这真的很烦人,我找不到任何方法来解决这个问题。
    • @Piotr:我现在已经通过升级所有内容并首先使用 aspectj 编译器构建来解决它,因此 eclipse 会捕获错误并报告它们。其次是编译/编织和增强我的源文件的 e2builder。最后一步是检查:Window->Preferences->General->Workspace->'Refresh automatically' 告诉 Eclipse 从磁盘重新加载生成/编译的源代码。
    【解决方案2】:

    除了自动编译之外,您还应该检查是否启用了 JDT 编织插件。

    窗口 |优先;单击 JDT Weaving 部分 - 验证它当前已启用。当您第一次安装插件时,它会询问您是否要启用此功能,但如果您回答“否”,它可能会被关闭。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-14
      • 2019-10-08
      • 1970-01-01
      • 2012-11-10
      • 2016-08-15
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      相关资源
      最近更新 更多