简体   繁体   中英

AspectJ compile-time weaving and Scala

Is it possible to have a Scala Maven project and weave AspectJ aspects at compile-time within the Scala classes?

I've been able to get load-time weaving to work but so far no success with compile-time.

The aspects are simply not woven into the Scala classes. From what I understand, compile-time weaving requires a specific Java compiler (AspectJ Compiler aka ajc). It is my understanding that ajc cannot compile Scala.

Is there an ajc equivalent for Scala? Or perhaps another way to get compile-time weaving to work with Scala?

Answer 1 isn't true compile-time weaving - it's binary weaving of already-compiled classes. It wouldn't work, for instance, if your scala classes needed the aspects to compile properly. I think the issue of compile-time weaving in scala is still an open question.

We agree with the assessment by the original poster that ajc is unlikely to know how to compile scala.

How about using AJC's -inpath switch? It accepts .class files in directories or JARs and weaves into them. Your Scala compiles to .class files, so that ought to work. No doubt you have the AJC docs, but here's a link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM