AspectJ - compilation time and load time

I am having trouble understanding the aspects of compiling timeJ and loading in time and figuring out what to use (and how to use ajc) to compile and build my project.

Here is my project structure: -

  • TestProject: java service library. It is used by several other projects. This project does not contain any aspects.

  • TestProject-Aspects: Contains only aspects that give advice to several classes in TestProject. I do not use AspectJ5 Annotation Style and all of my junction points are just a method at the moment.

My questions:

  • ajc vs iajc and how are they different?
  • Is there a need for weaving?

  • Will there be something like this work?

Compile test objects

<iajc> sourceroots=${sources.dir} destdir=${classes.dir} classpath=${standard.compile.classpath} </iajc> 

Compile a test project

 <iajc> sourceroots=${sources.dir} destdir=${classes.dir} classpath=${standard.compile.classpath} inpath=${[TestProject-Aspects]pkg.classpath} </iajc> 
  • Shouldn't I use javac at all? which I originally used to compile TestProject?
+4
source share
1 answer

ajc and iajc are extensions to the JDT compiler that ships with Eclipse. Thus, ajc and iajc will create exactly the same byte code for pure Java as Eclipse (which contains some minor differences from Oracle javac).

ajc and iajc are basically the same, except that iajc is incremental (i in iajc). This means that the compiler checks the timestamps and makes a more reasonable incremental build, if possible, and avoids full builds (just like when using AJDT inside eclipse). In addition to this functionality, they are essentially the same. See here for more information:

http://www.eclipse.org/aspectj/doc/released/devguide/antTasks-iajc.html

If the project does not contain aspects, the use of the ajc compiler is optional. These projects can be included in the inpath of a project that contains aspects. To compile elements containing aspects of the code style, you need to use ajc.

Aspects of design style are slightly different. If you use annotation style only for LTW, you can use javac to compile them until the correct aop.xml file is created, which will be available at runtime.

However, for CTW weaving annotation style, ajc is required.

In your specific case above, you can compile TestProject with javac if it is on the way to your aspect project. This would mean that the class files of your TestProject would be overwritten and merged with the class files from your aspect project.

Or, if you use LTW, you do not need to add your TestProject to any inpath, and you can use javac. But you must configure the application for LTW at runtime.


EDIT

To answer your comment below:

Yes. First, you can compile the aspect design using ajc or the iajc task. You can then compile your second, clean Java project using the iajc task as well and, in addition, putting the results of your first project on the aspect path. You cannot use javac for this at all.

The ant build.xml snippet will look something like this:

 <project name="simple-example" default="compile" > <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"> <classpath> <pathelement location="${home.dir}/tools/aspectj/lib/aspectjtools.jar"/> </classpath> </taskdef> <target name="compile" > <iajc sourceroots="${home.dir}/TestProject-Aspects/src" classpath="${home.dir}/tools/aspectj/lib/aspectjrt.jar" destDir="${home.dir}/TestProject-Aspects/bin"/> <iajc sourceroots="${home.dir}/TestProject/src" classpath="${home.dir}/tools/aspectj/lib/aspectjrt.jar" destDir="${home.dir}/TestProject/bin" aspectPath="${home.dir}/TestProject-Aspects/bin"/> </target> </project> 

See iajc here for more iajc :

http://www.eclipse.org/aspectj/doc/released/devguide/antTasks-iajc.html

+5
source

Source: https://habr.com/ru/post/1346278/


All Articles