steevn
steevn

Reputation: 242

using AspectJ in a plugin java project

i am working with Eclipse , i am trying to develop a plugin which uses Aspects ( Aspect J ), however i can not create Aspects outside an Aspect J project, even when i import the Aspect J project to the plugin one, any solution ?

for example when i run some methods via my plugin, the aspect capture the trace of every void method, and print a simple message.

public aspect MyAspect {

pointcut test() : call(public void *());

before() : test() {
    System.out.println("THIS advice code is executed before any call");
}
}

thanks

Upvotes: 0

Views: 407

Answers (1)

kriegaex
kriegaex

Reputation: 67297

In Eclipse there does not seem to be a GUI option to add natures to a project, only to convert the project into a nature. You need the AspectJ nature, though. You can edit the project files like this and see if it works. It seems to, at least. I tried really quickly, without actually adding aspects to the sample plugin project I opened after editing the files. I saw the little "AJ" icon and AspectJ-related menu entries, though.

I am just showing what you need to add. I guess there is nothing you need to remove, only maybe the <buildCommand> for the javabuilder because in a fresh AspectJ project there is just the ajbuilder (it also compiles plain Java files).

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>...</name>
    <!-- ... -->
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.ajdt.core.ajbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <!-- ... -->
    </buildSpec>
    <natures>
        <nature>org.eclipse.ajdt.ui.ajnature</nature>
        <!-- ... -->
    </natures>
</projectDescription>

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <!-- ... -->
    <classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
    <!-- ... -->
</classpath>

Upvotes: 2

Related Questions