maven bad class javax.annotation.PostConstruct
For java < 1.6 you need to use this dependency to get the JSR-250 annotations such as PostConstruct
<dependency>
<!-- Only bundled with java 1.6+ -->
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
sarmahdi
Updated on June 21, 2022Comments
-
sarmahdi about 2 years
I am trying to build a war project. and on compile it gives me this error:
[compiler:compile] Compiling 432 source files to C:\Beta\ECORP5\ECORP5-web\target\classes ------------------------------------------------------------- COMPILATION ERROR : ------------------------------------------------------------- \Beta\fin\fin-web\src\main\java\com\comp\fin\utils\Formatter.java:[23,-1] cannot access javax.annotation.PostConstruct bad class file: C:\Beta\fin\fin-web\target\endorsed\javaee-endorsed-api-6.0.jar(javax/annotation/PostConstruct.class) class file has wrong version 50.0, should be 49.0 1 error
I am not able to get rid of this error. I am using java 6 and jdk 1.5 here is my POM.xml or part of it without unrelated stuff:
> <**?**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>
I am using NetBeans IDE to create an ear project and this is the POM of the war module. I am building it separately. I dont think that should be a problem.
I will appreciate if some one can tell me what is wrong here that it gives this error.
On a side note: When I created the Maven Ear project it was using JavaEE 6 so the war module was also using Java EE 6 but when I added some files in the webApp directory of the war module the Java EE version changed in the war module properties to Java EE 1.4 I don't know how it is doing that and why or which file is making it change on module level.
-
AHungerArtist over 12 yearsThat right there is the problem. You need to get it back on using a higher Jave EE version. That's what that mismatch is telling you.
-
dma_k over 12 yearsIt looks like your maven-compiler-plugin as at 1.5 level. Check it.
-