Search Results

Search found 56 results on 3 pages for 'aspectj'.

Page 1/3 | 1 2 3  | Next Page >

  • Maven: compile aspectj project containing Java 1.6 source

    - by gmale
    What I want to do is fairly easy. Or so you would think. However, nothing is working properly. Requirement: Using maven, compile Java 1.6 project using AspectJ compiler. Note: Our code cannot compile with javac. That is, it fails compilation if aspects are not woven in (because we have aspects that soften exceptions). Questions (based on failed attempts below): Either 1) How do you get maven to run the aspectj:compile goal directly, without ever running compile:compile? 2) How do you specify a custom compilerId that points to your own ajc compiler? Thanks for any and all suggestions. These are the things I've tried that have let to my problem/questions: Attempt 1 (fail): Specify aspectJ as the compiler for the maven-compiler-plugin: org.apache.maven.plugins maven-compiler-plugin 2.2 1.6 1.6 aspectj org.codehaus.plexus plexus-compiler-aspectj 1.8 This fails with the error: org.codehaus.plexus.compiler.CompilerException: The source version was not recognized: 1.6 No matter what version of the plexus compiler I use (1.8, 1.6, 1.3, etc), this doesn't work. I actually read through the source code and found that this compiler does not like source code above Java 1.5. Attempt 2 (fail): Use the aspectJ-maven-plugin attached to the compile and test-compile goals: org.codehaus.mojo aspectj-maven-plugin 1.3 1.6 1.6 compile test-compile This fails when running either: mvn clean test-compile mvn clean compile because it attempts to execute compile:compile before running aspectj:compile. As noted above, our code doesn't compile with javac--the aspects are required. So mvn would need to skip the compile:compile goal altogether and run only aspectj:compile. Attempt 3 (works but unnacceptable): Use the same configuration above but instead run: mvn clean aspectj:compile This works, in that it builds successfully but it's unacceptable in that we need to be able to run the compile goal and the test-compile goal directly (m2eclipse auto-build depends on those goals). Moreover, running it this way would require that we spell out every goal we want along the way (for instance, we need resources distributed and tests to be run and test resources deployed, etc)

    Read the article

  • Maven + AspectJ - all steps to configure it

    - by Alice
    I have a problem with applying aspects to my maven project. Probably I am missing something, so I've made a list of steps. Could you please check if it is correct? Let say in projectA is an aspect class and in projectB classes, which should be changed by aspects. Create maven project ProjectA with AspectJ class add Aspectj plugin and dependency Add ProjectA as a dependency to projectB pom.xml Add to projectB pom.xml plugin " <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> <configuration> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> <aspectLibraries> <aspectLibrary> <groupId>ProjectA</groupId> <artifactId>ProjectA</artifactId> </aspectLibrary> </aspectLibraries> </configuration> </plugin> Add aspectj dependency After all these steps my problem is, that during compilation I get: [WARNING] advice defined in AspectE has not been applied [Xlint:adviceDidNotMatch] And then when I run my program: Exception in thread "FeatureExcutionThread" java.lang.NoClassDefFoundError: AspectE

    Read the article

  • Eclipse: How to convert a web project into an AspectJ project and weave and run it using the AJDT pl

    - by Kent
    What I want to do: I want to use the @Configured annotation with Spring. It requires AspectJ to be enabled. I thought that using the AJDT plugin for compile time weaving would solve this problem. Before installing the plug in the dependencies which were supposed to be injected into my @Configured object remained null. What I have done: Installed the AJDT: AspectJ Development Tools plug in for Eclipse 3.4. Right clicked on my web project and converted it into a AspectJ project. Enabled compile time weaving. What doesn't work: When I start the Tomcat 6 server now, I get an exception*. Other information: I haven't configured anything in the AspectJ Build and AspectJ Compiler parts of the project properties. JDT Weaving under Preferences says weaving is enabled. I still have Java build path and Java Compiler under project properties. And they look like I previously configured them (while the above two new entries are not configured). The icon of my @Configured object file looks like any other file (i.e. no indication of any aspect or such, which I think there should be). The file name is MailNotification.java (and not .aj), but I guess it should still work as I'm using a Spring annotation for AspectJ? I haven't found any tutorial or similar which teaches: How to turn a Spring web application project into an AspectJ project and weave aspects into the files using the AJDT plugin, all within Eclipse 3.4. If there is anything like that out there I would be very interested in knowing about it. What I would like to know: Where to go from here? I just want to use the @Configured annotation of Spring. I'm also using @Transactional which I think also needs AspectJ. If it is possible I would like to study AspectJ as little as possible as long as my needs are met. The subject seems interesting, but huge, all I want to do is use the above two mentioned Spring annotations. *** Exception when Tomcat 6 is started: Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:82) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1322) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) ... 41 more

    Read the article

  • Spring aspectj jar not configured correctly

    - by newguy
    I am getting this error when I tried to use a JPA object created by Roo. Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?) I have followed some online advice to add the spring-aspects.jar to aspectj path in Eclipse but I still get this error. Does anyone know how to solve this? The environment I am using is Spring 3.0.5, Hibernate 3.6 and JBoss 6.0.0.Final.

    Read the article

  • AspectJ join point with simple types

    - by Jon
    Hi! Are there defined join points in arithmetics that I can catch? Something like: int a = 4; int b = 2; int c = a + b; Can I make a pointcut that catches any one of those lines? And what context will I be able to get? I would like to add a before() to all int/float/double manipulation done in a particular method on a class, is that possible. I see in the AspectJ docs that there are defined join points for object initialization and method calls. Is declaring an int an object initialization and does the + operator count as a method call? Thanks!

    Read the article

  • handling multiple Aspects in AspectJ

    - by rajank
    I have a query, when im using multiple Aspects in my aop.xml. here's the problem. i have defined some <include> and <exclude> in my <weaver>. i have 3 aspects in my aop file. i need to define a specific <include> and <exclude> for each aspects. how it is possible. Thanks in advance.

    Read the article

  • Placing advice on any parameter of a given type in AspectJ

    - by user12558
    Hi, Im doing a POC using Aspectj. class BaseInfo{..} class UserInfo extends BaseInfo{..} class UserService { public void getUser(UserInfo userInfo){..} public void deleteUser(String userId){..} } I've defined an advice, that gets invoked when I pass an UserInfo instance.But when i try to pass the BaseInfo, the advice is not getting invoked. Below block executes the afterMethod as expected for getUser. &ltaop:pointcut id="aopafterMethod" expression="execution(* UserService.*(..,UserInfo,..))" / &gtaop:after pointcut-ref="aopafterMethod" method="afterMethod" / But when i try to give BaseInfo instead of UserInfo, the aspect is not getting triggered. Am i missing something? Kindly help me on this issue.

    Read the article

  • How to define an aspectj pointcut that picks out all constructors of a class that has a specific annotation?

    - by PineForest
    Here is the annotation: @Target(value = ElementType.TYPE) @Retention(value = RetentionPolicy.RUNTIME) @Inherited public @interface MyAnnotation { String name(); } Here is one annotated class: @MyAnnotation(name="foo") public class ClassA { public ClassA() { // Do something } } Here is a second annotated class: @MyAnnotation(name="bar") public class ClassB { public ClassB(String aString) { // Do something } } I am looking for an aspectj pointcut that correctly matches the constructors for ClassA and ClassB while not matching any other constructor for any other class NOT annotated by MyAnnotation.

    Read the article

  • Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.0

    - by alexm
    I switched from q4e Helios to Indigo m2e plugin and my Maven 2 project no longer works. I had a ROO-generated Spring MVC project. This is what I get: Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.0:test-compile (execution: default, phase: process-test-sources) Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (execution: default, phase: process-sources) Any insight is greatly appreciated. Thank you.

    Read the article

  • How to access private static target field in aspect in AspectJ?

    - by LihO
    I have a simple class Main with private static int x and an aspect that should output the old value of x before it is reassigned: public class Main { private static int x; public static void main(String[] args) { foo(7); } public static void foo(int y) { x = y; } } and MonitorX.aj: public aspect MonitorX { before() : set(static int Main.x){ System.out.println(Main.x); } } which doesn't work since I can't access private x using Main.x. I've also tried: before(int t) : set(static int Main.x) && target(t){ System.out.println(t); } which doesn't work either (nothing is outputted, if I try to output string, it seems that the aspect isn't invoked at all). However printing out the new value that is being assigned works: before(int newVal) : set(static int Main.x) && args(newVal){ System.out.println(newVal); } What am I missing?

    Read the article

  • How to capture button click if more than one button in AspectJ?

    - by aysenur
    Hi all, I wonder if we can capture that which button is clicked if there are more than one button. On this example, can we reach //do something1 and //do something2 parts with joinPoints? public class Test { public Test() { JButton j1 = new JButton("button1"); j1.addActionListener(this); JButton j2 = new JButton("button2"); j2.addActionListener(this); } public void actionPerformed(ActionEvent e) { //if the button1 clicked //do something1 //if the button2 clicked //do something2 } }

    Read the article

  • How to override ant task stored in ant lib directory

    - by mchr
    At my work we use AspectJ in some of our Java projects. To get this to work with ant builds we have been placing aspectjtools.jar within ant/lib/. I am now working on a particular Java project and need to use a newer version of aspectJ. I don't want to have to get everyone who uses the project to update their local copy of aspectjtools.jar. Instead, I tried adding the newer aspectjtools.jar to the lib directory of the project and adding the following line to build.xml. <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties" classpath="./lib/aspectjtools.jar" /> However, this doesn't work as I hoped as the ANT classloader loads jars from ant/lib/ in preference to the jar I specify in the taskdef classpath. Is there any way to force ant to pick the jar checked into my project instead?

    Read the article

  • How to declare a warning on field with AspectJ

    - by Ralph
    I want to declare a warning on all fields Annotated with @org.jboss.weld.context.ejb.Ejb in AspectJ. But I do not find a way how to select that field. I guess the aspect should be something like that: public aspect WrongEjbAnnotationWarningAspect { declare warning : within(com.queomedia..*) && ??? (@org.jboss.weld.context.ejb.Ejb) : "WrongEjbAnnotationErrorAspect: use javax.ejb.EJB instead of weld Ejb!"; } Or is it impossible to declare warnings on fields at all?

    Read the article

  • Spring Dependency Injecting an annotated Aspect

    Using Spring I've had some issues with doing a dependency injection on an annotated Aspect class. CacheService is injected upon the Spring context's startup, but when the weaving takes place, it says that the cacheService is null. So I am forced to relook up the spring context manually and get the bean from there. Is there another way of going about it? Here is an example of my Aspect: import org.apache.log4j.Logger; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import com.mzgubin.application.cache.CacheService; @Aspect public class CachingAdvice { private static Logger log = Logger.getLogger(CachingAdvice.class); private CacheService cacheService; @Around("execution(public *com.mzgubin.application.callMethod(..)) &&" + "args(params)") public Object addCachingToCreateXMLFromSite(ProceedingJoinPoint pjp, InterestingParams params) throws Throwable { log.debug("Weaving a method call to see if we should return something from the cache or create it from scratch by letting control flow move on"); Object result = null; if (getCacheService().objectExists(params))}{ result = getCacheService().getObject(params); } else { result = pjp.proceed(pjp.getArgs()); getCacheService().storeObject(params, result); } return result; } public CacheService getCacheService(){ return cacheService; } public void setCacheService(CacheService cacheService){ this.cacheService = cacheService; } }

    Read the article

  • spring 3 AOP anotated advises

    - by Art79
    Trying to figure out how to Proxy my beans with AOP advices in annotated way. I have a simple class @Service public class RestSampleDao { @MonitorTimer public Collection<User> getUsers(){ .... return users; } } i have created custom annotation for monitoring execution time @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface MonitorTimer { } and advise to do some fake monitoring public class MonitorTimerAdvice implements MethodInterceptor { public Object invoke(MethodInvocation invocation) throws Throwable{ try { long start = System.currentTimeMillis(); Object retVal = invocation.proceed(); long end = System.currentTimeMillis(); long differenceMs = end - start; System.out.println("\ncall took " + differenceMs + " ms "); return retVal; } catch(Throwable t){ System.out.println("\nerror occured"); throw t; } } } now i can use it if i manually proxy the instance of dao like this AnnotationMatchingPointcut pc = new AnnotationMatchingPointcut(null, MonitorTimer.class); Advisor advisor = new DefaultPointcutAdvisor(pc, new MonitorTimerAdvice()); ProxyFactory pf = new ProxyFactory(); pf.setTarget( sampleDao ); pf.addAdvisor(advisor); RestSampleDao proxy = (RestSampleDao) pf.getProxy(); mv.addObject( proxy.getUsers() ); but how do i set it up in Spring so that my custom annotated methods would get proxied by this interceptor automatically? i would like to inject proxied samepleDao instead of real one. Can that be done without xml configurations? i think should be possible to just annotate methods i want to intercept and spring DI would proxy what is necessary. or do i have to use aspectj for that? would prefere simplest solution :- ) thanks a lot for help!

    Read the article

  • Spring AOP pointcut that matches annotation on interface

    - by seanizer
    Hello, this is my first post here, so I apologize in advance for any stupidity on my side. I have a service class implemented in Java 6 / Spring 3 that needs an annotation to restrict access by role. I have defined an annotation called RequiredPermission that has as its value attribute one or more values from an enum called OperationType: public @interface RequiredPermission { /** * One or more {@link OperationType}s that map to the permissions required * to execute this method. * * @return */ OperationType[] value();} public enum OperationType { TYPE1, TYPE2; } package com.mycompany.myservice; public interface MyService{ @RequiredPermission(OperationType.TYPE1) void myMethod( MyParameterObject obj ); } package com.mycompany.myserviceimpl; public class MyServiceImpl implements MyService{ public myMethod( MyParameterObject obj ){ // do stuff here } } I also have the following aspect definition: /** * Security advice around methods that are annotated with * {@link RequiredPermission}. * * @param pjp * @param param * @param requiredPermission * @return * @throws Throwable */ @Around(value = "execution(public *" + " com.mycompany.myserviceimpl.*(..))" + " && args(param)" + // parameter object " && @annotation( requiredPermission )" // permission annotation , argNames = "param,requiredPermission") public Object processRequest(final ProceedingJoinPoint pjp, final MyParameterObject param, final RequiredPermission requiredPermission) throws Throwable { if(userService.userHasRoles(param.getUsername(),requiredPermission.values()){ return pjp.proceed(); }else{ throw new SorryButYouAreNotAllowedToDoThatException( param.getUsername(),requiredPermission.value()); } } The parameter object contains a user name and I want to look up the required role for the user before allowing access to the method. When I put the annotation on the method in MyServiceImpl, everything works just fine, the pointcut is matched and the aspect kicks in. However, I believe the annotation is part of the service contract and should be published with the interface in a separate API package. And obviously, I would not like to put the annotation on both service definition and implementation (DRY). I know there are cases in Spring AOP where aspects are triggered by annotations one interface methods (e.g. Transactional). Is there a special syntax here or is it just plain impossible out of the box. PS: I have not posted my spring config, as it seems to be working just fine. And no, those are neither my original class nor method names. Thanks in advance, Sean PPS: Actually, here is the relevant part of my spring config: <aop:aspectj-autoproxy proxy-target-class="false" /> <bean class="com.mycompany.aspect.MyAspect"> <property name="userService" ref="userService" /> </bean>

    Read the article

  • Maven can't recognize the dependencies in both local and server

    - by Gary
    The dependencies already be available in both local and server, but maven build(clean, install) still failed and complain that can't find them. 1 Although the dependency can be found in server, but failed to build online Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/aspectj-maven-plugin/1.4/aspectj-maven-plugin-1.4.pom [WARNING] Unable to get resource 'org.codehaus.mojo:aspectj-maven-plugin:pom:1.4' from repository central (http://repo1.maven.org/maven2): (http://repo1.maven.org/maven2%29:) Authorization failed: Access denied to: h ttp://repo1.maven.org/maven2/org/codehaus/mojo/aspectj-maven-plugin/1.4/aspectj-maven-plugin-1.4.pom 2 I try to try offline, as the dependency is already in local, but failed [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Failed to resolve artifact. GroupId: org.codehaus.mojo ArtifactId: aspectj-maven-plugin Version: 1.4 Reason: System is offline. org.codehaus.mojo:aspectj-maven-plugin:pom:1.4 3 BTW, i have configured the relevant profile for the server

    Read the article

  • How to create an aspect on class, that is not a bean using Spring AOP?

    - by Ula Krukar
    Hello, I work on an legacy application, where Spring AOP (namely ProxyFactoryBean) is used. I need to add an aspect around a method of a certain class. This class is not a bean however. The AspecjJ pointcut expression would be like this: execution(* xyz.package.Class.method()) I created a MethodInterceptor and AspectJExpressionPointcut, but I don't know how make those two work together. EDIT: I do not have source code for this class, it is a 3rd party library. The instances of this class are not created by me, neither in source code, nor in spring configuration as beans. It is used internally by the library. Any help appreciated.

    Read the article

  • Reading annotation property in aspect

    - by Lukasz Koniecki
    How to read annotation property value in aspect? I want my Around advice to be executed for all joint points annotated with @Transactional(readonly=false). @Around("execution(* com.mycompany.services.*.*(..)) " + "&& @annotation(org.springframework.transaction.annotation.Transactional)") public Object myMethod(ProceedingJoinPoint pjp) throws Throwable { }

    Read the article

  • Entity Aspect (in Spring)

    - by niklassaers
    Hi guys, I'm having a bit of a problem defining my aspects. I've got a bunch of entities that I'd like to profile the get-methods in, so I've written the following pointcut and method @Pointcut("execution(* tld.myproject.data.entities.*.get*()") public void getEntityProperty() {} @Around("getEntityProperty()") public Object profileGetEntityProperty(ProceedingJoinPoint pjp) throws Throwable { long start = System.currentTimeMillis(); String name = pjp.getSignature().getName(); Object output = pjp.proceed(); long elapsedTime = System.currentTimeMillis() - start; if(elapsedTime > 100) System.err.println("profileGetEntityProperty: Entity method " + name + " execution time: " + elapsedTime + " ms."); return output; } I've got weaving turned on in my configuration, and aspects weaving into the business layer work just fine. Is my pointcut correctly written? Or is there something about entities that make them non-weavable? (my entity is prefixed with @Entity before the class definition) Cheers Nik

    Read the article

  • Insert code into a method - Java

    - by DutrowLLC
    Is there a way to automatically insert code into a method? I have the following and I would like to insert the indicated code: public class Person { Set<String> updatedFields = new LinkedHashSet<String>(); String firstName; public String getFirstName(){ return firstName; } boolean isFirstNameChanged = false; // Insert public void setFirstName(String firstName){ if( !isFirstNameChanged ){ // Insert isFirstNameChanged = true; // Insert updatedFields.add("firstName"); // Insert } // Insert this.firstName = firstName; } } I'm also not sure if I can the subset of the method name as a string from inside the method itself as indicated on the line where I add the fieldName as a string into the set of updated fields: updatedFields.add("firstName");. And I'm not sure how to insert fields into a class where I add the boolean field that tracks if the field has been modified or not before (for efficiency to prevent having to manipulate the Set): boolean isFirstNameChanged = false; It seems to most obvious answer to this would be to use code templates inside eclipse, but I'm concerned about having to go back and change the code later.

    Read the article

1 2 3  | Next Page >