Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Build-time weaving with @Configurable

  1. #11
    Join Date
    Aug 2004
    Location
    Berne, Switzerland
    Posts
    42

    Default

    I have @Configurable running with both build-time and load-time weaving. Although the LTW version has a problem with the Spring 2.0rc3 because of a bug in AspectJ 1.5.2 (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=153572).

    I have just perpared a small eclipse project showing the build-time weaving in an Eclipse AJDT project. You need the same configuration in the spring context as with LTW.

    Code:
       <aop:spring-configured/>
        
        <bean class="com.trivadis.aop.configurable.Address" singleton="false">
        	<property name="codeRepository" ref="codeRepository"/>
        </bean>
        
    	<bean id="codeRepository" class="com.trivadis.aop.configurable.CodeRepositoryImpl"/>
    Then you have to add spring-aspects.jar to the AspectJ Aspect Path, because that's where the aspect handling the @Configurable can be found. The same can of course also be done with Maven or Ant.

    I've uploaded the sample eclipse project with this post. Just run the unit test in ConfigurableTest.

    Hope it helps!
    Attached Files Attached Files
    Guido Schmutz
    Principal Consultant, Trivadis Switzerland
    Email: guido.schmutz AT trivadis.com

  2. #12
    Join Date
    Aug 2004
    Location
    Los Angeles, USA
    Posts
    62

    Default

    That worked for me. Thanks a lot!

  3. #13
    Join Date
    Oct 2004
    Posts
    151

    Default

    Hi!

    Thank you for posting this description and code example!

    This made me understand how to make our unittests run from inside eclipse when built by eclipse.

    Until now the unittests worked just fine when running them from maven. When running them from eclipse we had to let maven do the compiling before running the tests if we had changed any of the classes using @Configurable to get dependencies injected

    The next step was to make maven generate correct .project og .classpass file for us and we almost do that now with the following in pom.xml:
    Code:
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
              <projectnatures>
                <java.lang.String>org.springframework.ide.eclipse.core.springnature</java.lang.String>
                <java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>
                <java.lang.String>org.eclipse.ajdt.ui.ajnature</java.lang.String>
              </projectnatures>
              <buildcommands>
                <buildcommand>org.eclipse.ajdt.core.ajbuilder</buildcommand>
              </buildcommands>
            </configuration>
          </plugin>
    What is missing here is generating the org.eclipse.ajdt.aspectpath attribute for the classpathentry in the .classpath file i.e.

    Code:
      <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aspects/2.0.6/spring-aspects-2.0.6.jar">
         <attributes>
            <attribute name="org.eclipse.ajdt.aspectpath" value="true"/>
         </attributes>
      </classpathentry>
    This is not possible today with maven-eclipse-plugin, but there is an issue for this feature in the jira for maven-eclipse-plugin, see

    http://jira.codehaus.org/browse/MECLIPSE-270

    Feel free to vote for this issue!

    btw are we using the following aspectj-maven-plugin configuration:
    Code:
          <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.0-beta-2</version>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>test-compile</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <source>1.5</source>
              <target>1.5</target>
              <encoding>iso-8859-1</encoding>
              <verbose>true</verbose>
              <outxml>false</outxml>
    
              <showWeaveInfo>true</showWeaveInfo>
              <proceedOnError>true</proceedOnError>
     
              <weaveDependencies>
                <weaveDependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-aspects</artifactId>
                </weaveDependency>
              </weaveDependencies>
    
              <aspectLibrarys>
                <aspectLibrary>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
              </aspectLibrarys>
    
            </configuration>
          </plugin>

    -Kaj
    Last edited by kajh; Sep 3rd, 2007 at 06:16 AM.

  4. #14
    Join Date
    Jan 2008
    Posts
    5

    Default My solution to the problem

    Here is the solution I am using to do weaving - http://anydoby.com/jblog/article.htm?id=61&lng=en

  5. #15
    Join Date
    Jan 2008
    Posts
    5

    Default

    Quote Originally Posted by kajh View Post
    Hi!

    Thank you for posting this description and code example!

    This made me understand how to make our unittests run from inside eclipse when built by eclipse.

    Until now the unittests worked just fine when running them from maven. When running them from eclipse we had to let maven do the compiling before running the tests if we had changed any of the classes using @Configurable to get dependencies injected

    The next step was to make maven generate correct .project og .classpass file for us and we almost do that now with the following in pom.xml:
    Code:
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
              <projectnatures>
                <java.lang.String>org.springframework.ide.eclipse.core.springnature</java.lang.String>
                <java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>
                <java.lang.String>org.eclipse.ajdt.ui.ajnature</java.lang.String>
              </projectnatures>
              <buildcommands>
                <buildcommand>org.eclipse.ajdt.core.ajbuilder</buildcommand>
              </buildcommands>
            </configuration>
          </plugin>
    What is missing here is generating the org.eclipse.ajdt.aspectpath attribute for the classpathentry in the .classpath file i.e.

    Code:
      <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aspects/2.0.6/spring-aspects-2.0.6.jar">
         <attributes>
            <attribute name="org.eclipse.ajdt.aspectpath" value="true"/>
         </attributes>
      </classpathentry>
    This is not possible today with maven-eclipse-plugin, but there is an issue for this feature in the jira for maven-eclipse-plugin, see

    http://jira.codehaus.org/browse/MECLIPSE-270

    Feel free to vote for this issue!

    btw are we using the following aspectj-maven-plugin configuration:
    Code:
          <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.0-beta-2</version>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>test-compile</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <source>1.5</source>
              <target>1.5</target>
              <encoding>iso-8859-1</encoding>
              <verbose>true</verbose>
              <outxml>false</outxml>
    
              <showWeaveInfo>true</showWeaveInfo>
              <proceedOnError>true</proceedOnError>
     
              <weaveDependencies>
                <weaveDependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-aspects</artifactId>
                </weaveDependency>
              </weaveDependencies>
    
              <aspectLibrarys>
                <aspectLibrary>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
              </aspectLibrarys>
    
            </configuration>
          </plugin>

    -Kaj
    Your solution will also include Spring aspects into the resulting jar file. How do you fix that?

  6. #16
    Join Date
    Oct 2004
    Posts
    151

    Default

    Quote Originally Posted by anydoby View Post
    Your solution will also include Spring aspects into the resulting jar file. How do you fix that?
    I'm not sure

    I include part of our pom.xml bellow. You might try to add that and see if it helps.

    btw... feel free to vote for http://jira.codehaus.org/browse/MECLIPSE-270

    Code:
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-aspects</artifactId>
             <version>2.5.1</version>
          </dependency>
         
         <dependency>
             <groupId>aspectj</groupId>
             <artifactId>aspectjweaver</artifactId>
             <version>1.5.3</version>
          </dependency>
          <dependency>
             <groupId>aspectj</groupId>
             <artifactId>aspectjrt</artifactId>
             <version>1.5.3</version>
          </dependency>
    
    ...     
         
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>aspectj-maven-plugin</artifactId>
              <version>1.0-beta-2</version>
                <executions>
                   <execution>
                      <goals>
                         <goal>compile</goal>
                         <goal>test-compile</goal>
                      </goals>
                   </execution>
                </executions>
                <configuration>
                   <source>1.5</source>
                   <target>1.5</target>
                   <encoding>utf-8</encoding>
                   <verbose>true</verbose>
                   <outxml>false</outxml>
    
                   <showWeaveInfo>true</showWeaveInfo>
                   <proceedOnError>true</proceedOnError>
    
                   <weaveDependencies>
                      <weaveDependency>
                         <groupId>org.springframework</groupId>
                         <artifactId>spring-aspects</artifactId>
                      </weaveDependency>
                   </weaveDependencies>
    
                   <aspectLibrarys>
                      <aspectLibrary>
                         <groupId>org.springframework</groupId>
                         <artifactId>spring-aspects</artifactId>
                      </aspectLibrary>
                   </aspectLibrarys>
    
                </configuration>
             </plugin>
    -Kaj

  7. #17
    Join Date
    Jan 2008
    Posts
    5

    Default new aspectj plugin

    I have investigated the issue of aspectj plugin including 3rd party aspects into my jars and realized that the plugin does not work for me. I was able to write my own plugin http://anydoby.com/jblog/article.htm?id=68&lng=en

    which works as I expect it to work

Posting Permissions

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