public aspect LoggingAspect { pointcut logExecution(): execution(* com.example.*.*(..)); before(): logExecution() { } after(): logExecution() { } } public class Example { public void foo() { } public void bar() { } public static void main(String[] args) { Example example = new Example(); example.foo(); example.bar(); } } <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.9.7</version> </dependency> <!-- other dependencies --> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.12.6</version> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> <configuration> <complianceLevel>1.8</complianceLevel> <source>1.8</source> <target>1.8</target> <Xlint>ignore</Xlint> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- other plugins --> </plugins> </build> bash ajc -source 1.8 -target 1.8 -cp path/to/aspectjrt.jar:path/to/your/library.jar \ -inpath path/to/your/library.jar \ -outjar wovenLibrary.jar \ path/to/your/source/files/*.java


上一篇:
下一篇:
切换中文