Java編程思想》中的注解代码中引入过这么一个包(com.sun.mirror),书上说的是在Jdk中有个tools.jar中,引入这个包就每这个问题了,但是笔者用的是JDK 1.8,把这个包import进来,代码还是一批报错。
实在没办法就在网上找,于是找到了apt-mirror-api-0.1.jar,它包含了以下内容:
Files contained in apt-mirror-api-0.1.jar:
META-INF/MANIFEST.MF
META-INF/maven/com.moparisthebest.aptIn16/apt-mirror-api/pom.properties
META-INF/maven/com.moparisthebest.aptIn16/apt-mirror-api/pom.xml
com.sun.mirror.apt.AnnotationProcessor.class
com.sun.mirror.apt.AnnotationProcessorEnvironment.class
com.sun.mirror.apt.AnnotationProcessorFactory.class
com.sun.mirror.apt.AnnotationProcessorListener.class
com.sun.mirror.apt.AnnotationProcessors.class
com.sun.mirror.apt.Filer.class com.sun.mirror.apt.Messager.class
com.sun.mirror.apt.RoundCompleteEvent.class
com.sun.mirror.apt.RoundCompleteListener.class
com.sun.mirror.apt.RoundState.class
com.sun.mirror.declaration.AnnotationMirror.class
com.sun.mirror.declaration.AnnotationTypeDeclaration.class
com.sun.mirror.declaration.AnnotationTypeElementDeclaration.class
com.sun.mirror.declaration.AnnotationValue.class
com.sun.mirror.declaration.ClassDeclaration.class
com.sun.mirror.declaration.ConstructorDeclaration.class
com.sun.mirror.declaration.Declaration.class
com.sun.mirror.declaration.EnumConstantDeclaration.class
com.sun.mirror.declaration.EnumDeclaration.class
com.sun.mirror.declaration.ExecutableDeclaration.class
com.sun.mirror.declaration.FieldDeclaration.class
com.sun.mirror.declaration.InterfaceDeclaration.class
com.sun.mirror.declaration.MemberDeclaration.class
com.sun.mirror.declaration.MethodDeclaration.class
com.sun.mirror.declaration.Modifier.class
com.sun.mirror.declaration.PackageDeclaration.class
com.sun.mirror.declaration.ParameterDeclaration.class
com.sun.mirror.declaration.TypeDeclaration.class
com.sun.mirror.declaration.TypeParameterDeclaration.class
com.sun.mirror.type.AnnotationType.class
com.sun.mirror.type.ArrayType.class
com.sun.mirror.type.ClassType.class
com.sun.mirror.type.DeclaredType.class
com.sun.mirror.type.EnumType.class
com.sun.mirror.type.InterfaceType.class
com.sun.mirror.type.MirroredTypeException.class
com.sun.mirror.type.MirroredTypesException.class
com.sun.mirror.type.PrimitiveType.class
com.sun.mirror.type.ReferenceType.class
com.sun.mirror.type.TypeMirror.class
com.sun.mirror.type.TypeVariable.class
com.sun.mirror.type.VoidType.class
com.sun.mirror.type.WildcardType.class
com.sun.mirror.util.DeclarationFilter.class
com.sun.mirror.util.DeclarationScanner.class
com.sun.mirror.util.DeclarationVisitor.class
com.sun.mirror.util.DeclarationVisitors.class
com.sun.mirror.util.Declarations.class
com.sun.mirror.util.SimpleDeclarationVisitor.class
com.sun.mirror.util.SimpleTypeVisitor.class
com.sun.mirror.util.SourceOrderDeclScanner.class
com.sun.mirror.util.SourcePosition.class
com.sun.mirror.util.TypeVisitor.class com.sun.mirror.util.Types.class
把这个包引进代码中就可以了。