Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AJC compiler and eclipse


You can achieve this in two ways.

Binary weaving or linked source folders.

Binary weaving
==============

This will probably give the *best performance*, but involves
(currently) a secret incantation that we haven't exposed
correctly in the UI.

Imagine you have a nice Java project that is building OK -
its output is being put in some bin location, e.g.
c:\eclipse\workspace\MyJavaProject\bin

And alongside I create an AspectJ project.  I write some
aspects and I want to apply them to my Java project.  What
you need to do is:
Open 'Project properties' for your AspectJ project.
Select 'AspectJ' in the list on the left hand side of
the project properties dialog.
On the right you can see a few things that can be set,
the top option 'Input jars' looks like what you want but
it isn't in this case.  You want to use another compiler
option that isn't exposed in that UI, -inpath.  So what
you have to do is enter, in the 'Non standard compiler options'
field, something like:

-inpath c:\eclipse\workspace\MyJavaProject\bin

Then click OK to shut down the project properties dialog.

Now, when you build your AspectJ project it will compile
your aspects and weave them against the class files from
the bin directory of your Java project.  What you will end
up with in the bin directory of your AspectJ project is a version
of your Java project classes woven with aspects.
The compiler is not repeating a build of your Java code, it is
only compiling your aspects from source to binary then doing a
weave of everything.

The downside of this is that AJDT doesn't provide you with feedback
about what got woven where, so the outline view for your aspects
won't show where they applied to your input classes.

===================================================================

Linked source folders
=====================

In your workspace, you have your normal Java project - no
aspects involved.  Ensure it works with a source folder
rather than having its src directly in the top level of the
project.

Alongside, create your AspectJ project.  Ensure it also works
using a source folder.

Now create a linked source folder in your AspectJ project:
Open 'Project Properties' for your AspectJ project.  Select
'Java Build Path' in the list on the left of the properties
page and then click the 'Source' tab.  Then click 'Add Folder'
and then 'Create New Folder'.  A 'New Source Folder' dialog will
appear.  In this dialog enter a name for your new src folder
'linked_src' or something and click 'Advanced' - the dialog
will expand and you can now enter a path for the linked source
folder.  Select 'Link to folder in the file system' and
click 'Browse', then navigate to the src folder for your
Java project.  Click OK to get out of these dialogs and
you should find a 'linked_src' folder entry in your 'Source
folders on build path' list.
Click OK to close the project properties dialog.

Now when you build your aspect project, it applies the aspects
to the source from your java project.  The bin directory for
your aspectj project will contain woven versions of your java
project code.

The upside of doing it this way is that you do see how the
advice in your aspects applies to your Java project.  The
downside is that AspectJ is still doing a full source -> binary
compilation of your Java project on every build.

===================================================================

Any help?

regards,
Andy.




"jan casteels" <jan_casteels@xxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

28/05/2004 09:50

Please respond to
aspectj-users

To
aspectj-users@xxxxxxxxxxx
cc
Subject
Re: [aspectj-users] AJC compiler and eclipse





Ok, we seem to have the same issues.

Is their someone that has experience in setting up eclipse with 2 projects

1. Normal eclipse project
Contains all the normal classes and is the normal project like most
developers are currently using it.
2. Aspect project that contains the aspects but uses the other project for
the classes
Developers can use this project to weave in the aspects.

What I am trying to achieve is to replace some Mock objects with aspects to
ease some of the unittesting


Jan


Back to the top