- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想将 AspectJ 与 Java 结合使用来打印程序中所有连接点的列表。
我在 this document 的第二页上找到了一个旧代码示例.
public aspect Logging {
before (): !within (aspects.*) {
System.out.println(thisJoinPointStaticPart);
}
}
主类如下所示:
public class Main {
public static void main(String[] args) {
methodeA();
}
public static void methodeA(){
}
}
遗憾的是,如果我使用 Eclipse Luna Service Release 2 (4.4.2) 运行此代码,则会发生异常:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Main.<clinit>(Main.java:1)
Caused by: org.aspectj.lang.NoAspectBoundException: Logging
at Logging.aspectOf(Logging.aj:1)
at Logging.<clinit>(Logging.aj)
... 1 more
我希望输出如下:
...
call(void Main.methodeA())
execution(void Main.methodeA())
最佳答案
可能是你的目录结构不对。您可以尝试使用以下小示例项目(基于您的代码)并可以通过 maven 执行。
假定的文件/目录结构
pom.xml
src/main/java/aspects/Logging.aj
src/main/java/Main.java
日志记录.aj
package aspects;
public aspect Logging {
before(): !within(aspects.*) {
System.out.println(thisJoinPointStaticPart);
}
}
主.java
public class Main {
public static void main(String[] args) {
methodeA();
}
public static void methodeA() {
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sub.optimal</groupId>
<artifactId>AspectJScratch</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
执行 mvn clean compile exec:java
将产生以下输出。
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ AspectJScratch ---
staticinitialization(Main.<clinit>)
execution(void Main.main(String[]))
call(void Main.methodeA())
execution(void Main.methodeA())
关于java - AspectJ 列出所有连接点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34871320/
我有以下情节 require(ggplot2) dtf <- structure(list(Variance = c(5.213, 1.377, 0.858, 0.613, 0.412, 0.229,
我可以捕获算术中定义的连接点吗? 类似于: int a = 4; int b = 2; int c = a + b; 我可以创建一个切入点来捕获这些行中的任何一行吗?我可以获得什么背景信息? 我想添加
我编写了以下代码,用于使用鼠标事件添加和删除点或圆。下一步是在创建它们时用一条线将它们连接起来(创建一个多边形)。我完全卡住了,不知道从哪里开始。我正在寻找文档,但如果有人能指出正确的方向,我将不胜感
我读过 Evans、Nilsson 和 McCarthy 等书,了解领域驱动设计背后的概念和推理;但是,我发现很难将所有这些放在一个真实世界的应用程序中。缺乏完整的例子让我摸不着头脑。我找到了很多框架
有没有办法在 Python 中创建 NTFS 连接点?我知道我可以调用 junction 实用程序,但最好不要依赖外部工具。 最佳答案 自 Python 3.5 以来,_winapi 模块中有一个函数
Swing (Java 1.6.0_u25) 中的 JFileChooser 似乎不知道如何处理 NTFS 连接点或符号链接(symbolic link)。 文件选择器没有特殊处理: int rv =
这个问题在这里已经有了答案: Check if a file is real or a symbolic link (9 个回答) 关闭 5 年前。 有谁知道如何检查文件或目录是否是符号链接(sym
我是一名优秀的程序员,十分优秀!