Results 1 to 7 of 7

Thread: Is there an alternative to AspectJ LTW?

  1. #1

    Default Is there an alternative to AspectJ LTW?

    Hi,

    We're using Spring 2.0 with AspectJ for Dependency Injection.
    So far we've been using LTW, but we would like to switch to Compile-Time Weaving, because it seems more reasonable for deployment, and because we have encountered some out-of-memory issues with LTW.

    Can anyone point me to some documentation on how to do this? The Spring reference doesn't seem to cover this (only LTW). We're using Eclipse, and I assume we need the AJDT. But assuming I've got LTW all configured, what changes, if any, do I need to make to my configuration files?

    Moreover, is the fact that Spring documentation focuses on LTW (and not on compile-time weaving) suggesting that LTW is the preferred/recommended way in Spring? In the Spring Reference, section 6.1.1 it says:
    Weaving: Linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring, like other pure Java AOP frameworks, performs weaving at runtime.
    Thanks in advance.

  2. #2
    Join Date
    Sep 2004
    Location
    Texas
    Posts
    155

    Default

    Compile-time weaving is nice for many reasons, not the least of is that you can catch any pointcut definition errors at compile-time, not after deployment.

    All it boils down to is using ajc instead of your regular java compiler, and you are good to go. None of this aop.xml crap.

    Both Ant and Maven2 support plugging in ajc as your compiler, and I have used both successfully. Here is an example Ant task:

    Code:
       <path id="aspectPath">
          <pathelement location="${spring.dir}/dist/spring-aspects.jar"/>
       </path>
    
       <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
          <classpath>
             <pathelement location="${aspectj.dir}/lib/aspectjtools.jar"/>
          </classpath>
       </taskdef>
    
       <target name="compile" depends="compileReports">
          <mkdir dir="${class.dir}"/>
          <delete>
             <fileset dir="${class.dir}">
                <include name="**/*"/>
             </fileset>
          </delete>
    
          <iajc sourceroots="${src.dir}" destdir="${class.dir}" classpathRef="classpath" aspectPathRef="aspectPath"
                source="1.5" target="1.5" showWeaveInfo="true"/>
    
          <mkdir dir="${temp.dir}/output"/>
       </target>
    And here is the Maven2 config:
    Code:
          <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>aspectj-maven-plugin</artifactId>
              <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <XnoInline>true</XnoInline>
              <aspectLibraries>
                  <aspectLibrary>
                    <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
              </aspectLibraries>
              <showWeaveInfo>true</showWeaveInfo>
              </configuration> 
              <executions>
                  <execution>
                      <goals>
                          <goal>compile</goal>      
                          <goal>test-compile</goal>  
                      </goals>
                  </execution>
             </executions>
          </plugin>
    You can check the ajc-related docs for more info.
    Corby

  3. #3

    Default Thanks

    Thanks, your input was very helpful.

    I got it working both using Ant and using the IDE (Eclipse + AJDT).

    I'm still curious, though, to hear some opinions regarding the pros and cons of each approach (compile-time vs load-time weaving). It seems as if the Spring folks are more inclined towards LTW, and I'd like to know why.

    Naaman

  4. #4
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default

    Quote Originally Posted by nlif View Post
    I'm still curious, though, to hear some opinions regarding the pros and cons of each approach (compile-time vs load-time weaving).
    Recently there was a very interesting thread in [aspectj-users] mailing list. You can follow the entire trail here.

    Cheers.
    - Debasish

  5. #5

    Default Thanks.

    Thanks, this was very helpful.

    I guess that from the Spring team's perspective, LTW is better, because they don't want to make an AspectJ enabled IDE a pre-requisite for using Spring. LTW may increase start-up time, but relieves developers from making changes to their working environment.

  6. #6

    Question Webflow Aspectj

    Hi I'm trying

    Load-Time Weaving (LTW) with Webflow as did you...

    I placed the aop.xml where my persistence.xml resides ( I'm hoping this gets recognized because of the errors I get)

    Code:
    <!DOCTYPE aspectj PUBLIC
            "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
        <weaver>
            <!-- only weave classes in this package will include subpkgs -->
            <include within="org.springframework.webflow.samples..*"/>
        </weaver>
        <aspects>
            <!-- use only this aspect for weaving -->
            <!-- <aspect name="org.springbyexample.aspectjLoadTimeWeaving.PerformanceAdvice" /> -->
            <aspect name="org.springframework.webflow.samples.util.ErrorLogger" />
        </aspects>
    </aspectj>
    In my main config I am trying to find what to put as weaver class?
    Code:
    <context:load-time-weaver  aspectj-weaving="on"  weaver-class="???"  />
    If nothing then ..
    Code:
    java.io.NotSerializableException: org.springframework.context.weaving.DefaultContextLoadTimeWeaver
    If I place the class (from spring-agent.jar) in the server and set the javaagent ../libs/Spring-agent.jar in the
    catalina.bat of Tomcat so that it starts
    Code:
    if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuli
    set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties -javaagent:../server/lib/spring-agent.jar"
    then it too is not serialized. So I then added "implements Serialization" to the class jar it put it in play,
    and get..
    Code:
    java.io.NotSerializableException: org.apache.catalina.loader.WebappClassLoader
    and so on with no hope of serializing the chain of implyed classes
    ( for this reason I feel I am on the wrong track...)

    Must I write some kind of Custom LoadTimeWeaving class and how could you do this?
    I saw the following config at http://www.springbyexample.org/examp...pectj-ltw.html
    but was unable to see/checkout the sc
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context.xsd">
    
        <context:load-time-weaver />
        
        <bean id="processor" class="org.springbyexample.aspectjLoadTimeWeaving.Processor" />
        
    </beans>
    In short, just how does one config and implement aspectj (LTW) for Webflow??
    I don't see anything out there really, is it possible?
    Webflow requires serialization for snapshots etc,...

    I just know there's something I'm missing/overlooked!

    Can anyone stear/help me in the right direction?

    There's just nothing on AOP for webflow in the manual or forums!



    Hope to hear from someone,

    Best Regards,

    John.

  7. #7
    Join Date
    Apr 2011
    Posts
    1

    Default

    Hi,

    Is there a way to use the aspectj-maven-plugin with fork? In ant it is possible, but in maven, as far as I know, not.
    From my point of view, this is a big disadvantage of Maven.

    Best Regards,
    Gabi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •