Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] aspectJ with packaged classes

When i am working with jars instead of source projects (for instance,
instead of the sources of the Java project and the source of the aspectJ
project, i have the two jars), then how does it work?

Are the jars built from each of the projects?
If so then your javaproject.jar will contain HelloWorld.class and your
aspectjproject.jar will contain the woven version of HelloWorld.class
and the compiled aspect YourAspect.class

You can then forget about javaproject.jar and just run your
aspectjproject.jar as that contains the woven version of the class you
are interested in.

If they are built *without* weaving.  For example, if you did not put
javaproject on the inpath for the aspectj project, and instead you
built the projects as two standalone jars:

javaproject.jar containing your unmodified helloworld.class
aspectjproject.jar containing your aspect class YourAspect.class

then you have a few options for running them, you can do a binary
weave offline to create a new jar containing the modified code:

ajc -inpath javaproject.jar -aspectpath aspectjproject.jar -outjar
wovenresult.jar

and then run
java -classpath aspectjrt.jar;wovenresult.jar HelloWorld

Or you can do load time weaving and use the AspectJ agent - I can't
quite remember the exact syntax but you would want to build the
AspectJ project such that it creates an aop.xml file (the aop.xml
lists the 'aspects' that are around) - the aop.xml is included in the
jar that you build for the project.  Then you can LTW with something
like (you need to check the doc to see what exactly this should be):

set CLASSPATH=aspectjrt.jar;aspectjproject.jar;javaproject.jar
java -javaagent:aspectjweaver.jar HelloWorld

and then the AspectJ agent will weave the aspect into HelloWorld as it
is loaded by the VM.

Going back to what you asked:
I was told to execute  it with the following command:

java -classpath ".:aspectjrt.jar:aspectproject.jar" -jar javaproject.jar

Doesn't this mean that i am execute the java project and not the aspectJ
project? Is there anyway i can execute the Java project (making it 'aware'
of the aspects from the aspectJ project) and get the benefits from aspectJ?

I would say use the LTW approach described above if you want to do
that.  There are then never two versions of your helloworld to worry
about, there is just the pure version HelloWorld.class and the
loadtime weaver will worry about applying aspects when it is executed.


Back to the top