maven bad class javax.annotation.PostConstruct

sar*_*hdi 1 war java-ee maven

我正在努力建立一个战争项目.并在编译它给我这个错误:

[编译:编译]将432个源文件编译为C:\ Beta\ECORP5\ECORP5-web\target\classes -------------------------- -----------------------------------编译错误:------------ -------------------------------------------------\Beta\fin\fin-web\src\main\java\com\comp\fin\utils\Formatter.java:[23,-1]无法访问javax.annotation.PostConstruct坏类文件:C:\ Beta\fin\fin-web\target\endorsed\javaee-endorsed-api-6.0.jar(javax/annotation/PostConstruct.class)类文件有错误的版本50.0,应该是49.0 1错误

我无法摆脱这个错误.我正在使用java 6和jdk 1.5这里是我的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>
>     <*parent>
>         <*artifactId>fin<*/artifactId>
>         <*groupId>com.comps<*/groupId>
>         <*version>1.0-SNAPSHOT<*/version>
>     <*/parent>
> 
>     <groupId>com.comps</groupId>
>     <artifactId>fin-web</artifactId>
>     <version>1.0-SNAPSHOT</version>
>     <packaging>war</packaging>
> 
>     <name>fin-web</name>
> 
>     <properties>
>         <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
>         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>     </properties>
> 
>     <dependencies>
>        
>         <dependency>
>             <groupId>javax</groupId>
>             <artifactId>javaee-web-api</artifactId>
>             **<version>6.0</version>**            
>         </dependency>
> 
>     </dependencies>
> 
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-compiler-plugin</artifactId>
>                 <version>2.3.2</version>
>                 <configuration>
>                     <**source>1.5</source>
>                     <target>1.5</target>**
>                     <compilerArguments>
>                         <endorseddirs>${endorsed.dir}</endorseddirs>
>                     </compilerArguments>
>                 </configuration>
>             </plugin>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-war-plugin</artifactId>
>                 <version>2.1.1</version>
>                 <configuration>
>                     <failOnMissingWebXml>false</failOnMissingWebXml>
>                 </configuration>
>             </plugin>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-dependency-plugin</artifactId>
>                 <version>2.1</version>
>                 <executions>
>                     <execution>
>                         <phase>validate</phase>
>                         <goals>
>                             <goal>copy</goal>
>                         </goals>
>                         <configuration>
>                             <outputDirectory>${endorsed.dir}</outputDirectory>
>                             <silent>true</silent>
>                             <artifactItems>
>                                 <artifactItem>
>                                     <groupId>javax</groupId>
>                                     <artifactId>javaee-endorsed-api</artifactId>
>                                     <version>6.0</version>
>                                     <type>jar</type>
>                                 </artifactItem>
>                             </artifactItems>
>                         </configuration>
>                     </execution>
>                 </executions>
>             </plugin>
>         </plugins>
>     </build>
> 
> </project>
Run Code Online (Sandbox Code Playgroud)

我正在使用NetBeans IDE创建一个ear项目,这是war模块的POM.我正在单独构建它.我不认为这应该是一个问题.

我会很感激,如果有人能告诉我这里有什么错误,它会给出这个错误.

旁注:当我创建Maven Ear项目时,它使用JavaEE 6,因此war模块也使用Java EE 6但是当我在war模块的webApp目录中添加了一些文件时,war EE模块中的Java EE版本发生了变化Java EE 1.4的属性我不知道它是如何做的以及为什么或哪个文件在模块级别上进行更改.

dan*_*ter 9

对于java <1.6,您需要使用此依赖项来获取JSC-250注释,例如PostConstruct

<dependency>
  <!--  Only bundled with java 1.6+ -->
  <groupId>javax.annotation</groupId>
  <artifactId>jsr250-api</artifactId>
  <version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)