MyJavaCode.com

Tutorial and How to Guide on Java Programming. Topics covered include Java Programming Language - Core Java, Spring, Webservices, REST, Hibernate, Maven and Microservices.

  • Core Java
  • REST API’s
  • Spring boot
  • Hibernate
  • Interview Questions
  • Contact Us
  • Projects
  • Offerings

How to Solve Maven invalid CEN header error

January 8, 2025 By Prasanna Manjunatha

While compiling or building a maven project, sometimes you may get an invalid CEN header (bad signature) error like below,

[INFO] Building OpenJavaProfiler 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ OpenJavaProfiler --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ OpenJavaProfiler --- 
[INFO] Changes detected - recompiling the module! 
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! 
[INFO] Compiling 6 source files to /mnt/01D6BA885EADB284/OpenJavaProfiler/OpenJavaProfiler/target/classes 
[ERROR] error reading /home/.m2/repository/org/javassist/javassist/3.22.0-GA/javassist-3.22.0-GA.jar; 
invalid CEN header (bad signature)

The “invalid CEN header” error in Maven typically suggests that there’s a problem with one or more of your JAR files. The issue can arise from various causes such as a corrupted download, problems during the JAR creation, or even issues with the repository from which the JAR was fetched. Here’s how you can resolve it:

Also Read: How to Password Protect a PDF File using Java : A Step-by-Step Guide

 

1. Clear Local Repository

The simplest step is to remove the problematic JAR from your local Maven repository. Maven caches artifacts in your local repo (usually located in ~/.m2/repository). By removing the corrupted JAR, Maven will fetch a fresh copy on your next build.

rm -rf ~/.m2/repository/path-to/problematic-artifact

Replace path-to/problematic-artifact with the appropriate path to the JAR or directory that’s causing the issue.

2. Force Update of Snapshots/Releases

Run Maven with the following command to force an update of snapshots and releases:

mvn clean install -U

The -U flag ensures that Maven will update snapshots and releases.

Also Read: What Are REST APIs? A Beginner’s Guide for Java Developers

3. Check Your Repository

If the problem persists,

  • Ensure you’re pulling from the correct repository.
  • Check if there’s a mirror or proxy (like Nexus or Artifactory) that might be serving the corrupted JAR. You might need to clear caches or correct issues there.

4. Download and Install Manually

If you know the source of the JAR, you can manually download it and install it to your local repository:

mvn install:install-file -Dfile=<path-to-jar> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=jar

Fill in <path-to-jar>, <group-id>, <artifact-id>, and <version> with appropriate values for the problematic artifact.

5. Verify Zip Integrity

Sometimes, the “invalid CEN header” error can be due to the JAR itself being corrupted. You can verify its integrity since JAR files are essentially zip archives:

unzip -t your.jar

If there’s a corruption, this command will indicate it.

Also Read: Getting Started with Spring Boot: A Spring Boot Setup Tutorial

6. Rebuild the Project

If the corrupted JAR is a result of your project’s build, consider doing a full clean build:

mvn clean install

7. Consider Proxy Issues

If you’re behind a corporate proxy, it might be messing with binary transfers. Make sure your Maven settings (settings.xml in ~/.m2/) are correctly configured to use the proxy.

email
print

About Prasanna Manjunatha

Prasanna is a Toronto based Java Consultant with more than 15 years of Software Development experience. His areas of expertise include Core Java, Spring boot, REST, Microservices, Hibernate, NoSQL, Docker, Kubernetes and AWS.

Currently Trending

Connect with us

  • Facebook
  • GitHub
  • LinkedIn
  • Twitter

TAG CLOUD

Axis2 CodeCoverage Code Coverage cron expression Data Structure Frameworks Hashing HashMap Hibernate IntelliJ java Java Mail jboss jpa 2.1 Maven MyBatis MySQL PDF Quartz REST REST API SOAP Spring boot Springboot SQL Tools Tutorial web service

All time Popular Posts

Copyright © 2025 MyJavaCode.com