Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused how ajc works with javac

I'm a little confused how the AspectJ compiler, ajc works. To my understanding when talking about CTW, ajc is used to weave aspects into the compiled byte-code - ie: the .class file.

However, when I look at the maven-plugin for AspectJ (aspectj-maven-plugin), it turns out that it is run in the generate-sources phase of maven, before the javac compiler. Which would imply that the compiler runs after the aspect weaving. That kind of makes sense, since you can weave in ITDs, modifying class members, etc. which the java compiler would need to know about in order to compile any dependent classes.

So if that is the case, and ajc runs before javac, I presume that ajc must first compile all the java code into byte code to be able to weave in any aspects.

So the question is, if ajc already goes through the efforts of compiling all the java code into byte code, why does javac even need to run at all? Why isn't ajc the only compiler that is required? Isn't having both run just duplicating the efforts? Additionally, how does javac handle the classes that ajc has already compiled? Does it just ignore them since there is no change in the source file since the .class file was generated?

like image 662
Eric B. Avatar asked Jan 23 '14 18:01

Eric B.


People also ask

What is the function of javac?

The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.

Is javac the compiler?

The Java programming language compiler, javac , reads source files written in the Java programming language, and compiles them into bytecode class files.

What is source and target in javac?

You use the -source option to specify the java version used for compilation and you use the -target option to specify the lowest java version to support. eg. If I specify a target of 1.4, then my program will not be able to run on java 1.3 or lower.


1 Answers

ajc can compile all the classes, its built on the eclipse java compiler. ajc is the only compiler that is required to generate classes.

as far as duplicated efforts, javac will most likely not overwrite .class files that have a newer timestamp than the source java file. also you can imagine builds where some of the sources are compiled with ajc, and some with javac.

as far as maven scheduling goes, i dont know.

like image 144
aepurniet Avatar answered Sep 18 '22 17:09

aepurniet