Thursday, May 18, 2017

try-with-resources is not supported in -source Or Set Compiler Source and Target

try-with-resources is not supported 
Some time we face issues while building java project with maven with error below:

  1. try-with-resources is not supported in -source 1.5 [ERROR]   (use -source 7 or higher to enable try-with-resources)
  2. diamond operator is not supported in -source 1.5[ERROR]   (use -source 7 or higher to enable diamond operator)

This problem can be resolved by providing the maven compile plugin in pom.xml.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

Here I have given the compile Jdk 1.8 as source and target. You can specify this version as per your requirement.

Source of this information is available at maven docs.

Saturday, September 17, 2016

invalid LOC header (bad signature)

D:\projects\checkout\spring\SpringMVCWebApp>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringMVCWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ SpringMVCWebApp ---
[INFO] Deleting D:\projects\checkout\spring\SpringMVCWebApp\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SpringMVCWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ SpringMVCWebApp ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\projects\checkout\spring\SpringMVCWebApp\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\ch\qos\logback\logback-classic\1.0.13\logback-classic-1.0.13.jar; invalid LOC header (bad signature)
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\ch\qos\logback\logback-core\1.0.13\logback-core-1.0.13.jar; invalid CEN header (bad signature)
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\org\springframework\spring-aop\4.1.1.RELEASE\spring-aop-4.1.1.RELEASE.jar; invalid LOC header (bad signatur
e)
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\org\springframework\spring-context\4.1.1.RELEASE\spring-context-4.1.1.RELEASE.jar; invalid CEN header (bad
signature)
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.998 s
[INFO] Finished at: 2016-09-18T08:42:33+05:30
[INFO] Final Memory: 7M/241M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project SpringMVCWebApp: Compilation failure: Compilat
ion failure:
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\ch\qos\logback\logback-classic\1.0.13\logback-classic-1.0.13.jar; invalid LOC header (bad signature)
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\ch\qos\logback\logback-core\1.0.13\logback-core-1.0.13.jar; invalid CEN header (bad signature)
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\org\springframework\spring-aop\4.1.1.RELEASE\spring-aop-4.1.1.RELEASE.jar; invalid LOC header (bad signatur
e)
[ERROR] error: error reading C:\Users\rajendar\.m2\repository\org\springframework\spring-context\4.1.1.RELEASE\spring-context-4.1.1.RELEASE.jar; invalid CEN header (bad
signature)
[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/MojoFailureException



Steps to resolve this issue:

1. go to 
          .m2\repository
2. Delete all jar those causing this compile issue.
3. run maven command from your project pom.xml location again 
         mvn clean install

Friday, April 17, 2015

Maven Error :

We some time face below error while building java project using Maven.
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project api: Fatal error compiling: invalid target release: 1.7

The reason for this error is jdk version mismatch in classpath variable and pom.xml.

Please change your variableJava_Home in classpath as per pom.xml or change variable in pom.xml as per Java_Home classpath.

Change Java_Home in classpath:
MyComputer ==> prperties ==> Advanc Settings ==> Environment Variables





Change here variable value as per above discussion.