Q: The import javax.annotation cannot be resolved during Maven build I am getting the following error while building a .war using mcn clean package with Apache Maven. Can some one give me a way to resolve it? Thanks.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.593s
[INFO] Finished at: Thu Sep 05 22:35:10 GMT+05:30 2013
[INFO] Final Memory: 13M/24M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (default) on project application: Compiler errors :
[ERROR] error at import javax.annotation.PreDestroy;
[ERROR] ^^^^^^^^^^^^^^^
[ERROR] C:\Documents and Settings\User\My Documents\application\application\src\main\java\com\Service\MyService.java:13:0::0 The import javax.annotation cannot be resolved
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


A: Does your pom.xml set the Java Compiler version?
Some (all?) versions of maven-compiler assume the Java 1.4 compiler... which of course causes issues since Annotations were new in Java 1.5.
You can force it to Java 7 by including a plugin block for maven-compiler-version in your project's pom.xml and set its source and target properties... something like this:
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>


A: Download JSR305 from here to fix the problem.
