maven build failure: cannot read zip file entry - maven

i am getting this exception when try to run as-> maven build
.m2\repository\commons-logging\commons-logging\1.1\commons-logging-1.1.jar; cannot read zip file entry
I've already spent a day on it , searched over google , but no luck
any idea how can i resolve this
thanks

Try to open the jar with a Zip utility (7Zip ou something else).
If it fails, delete the file from your local repository, and retry to run your app.
If it fails again, then you may have an issue with your Maven repos config.

If maven downloads corrupt jars (jars that do not open with a zip utility) - try downloading those perticular jars manually and replace them in the appropriate repository folder location.
In settings.xml specify the localRepository path explicitly. Using the default settings (i.e. not specifing localRepository) causes maven to download the jars again and again when you do a "clean install" and you end up have the corrupt jars again.

In my experience, it is caused by a corrupted zip file. A failed build often appends to the jar, but doesn't delete it, therefore producing an unreadable file.
The solution, as suggested, is to delete the jar, then try to download again from the repository (create a maven build with package goal) If that repeatedly fails, the remote location might be corrupted.

Delete the m2 repository folder and try running your maven ,it will download all the jar files again and the build success

Related

Creation of .m2 folder after deletion while working in eclipse

I am working on my first project on maven in Eclipse IDE and encountered an error that says following
"could not resolve repository"
then I was instructed to delete .m2 folder and build it again.
How do I build it again ?
Your .m2 folder contains a folder repository and a setttings.xml (if you created one). The repository contains cached artifacts from the remote repositories and your own built artifacts. If you don't need the artifacts you have build any more, you can savely delete the folder repository. This might help you resolve problems with broken cache.

How to change the location of Spring STS tool repository

I am getting the following error when run spring boot application.
Actually .m2 repository accidentally deleted. When re-running the application it is updated, but it is showing the following error. please do help in this regard.
Archive for required library:
C:/Users/Sathish/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.6/tomcat-embed-core-8.5.6.jar'
in project 'Application' cannot be read or is not a valid ZIP file
Looks like the mentioned JAR file in the local Maven repository is corrupt. I would delete this file manually from the repository, go back to STS, and run an "Maven -> Update Project...", maybe also checking the "Force Download of Snapshots/Releases". That should help.

Gradle doesn't download jars

I am working on a gradle project that should run on a machine without internet connection.
For that, I have created a task that takes the gradle cache and copies it into another directory, to be used as a local repository.
I have built the project in online mode and it worked.
I have ran my task to copy the cache to the local repository and it worked.
However, when trying to run gradle build --offline I am getting errors like this (for several different jar files):
Could not download commons-math3.jar (org.apache.commons:commons-math3:3.4.1): No cached version available for offline mode
Checking both my local repository and the gradle cache, I couldn't find the relevant jar file (in this case commons-math3-3.4.1.jar).
I have tried using gradle build --refresh-dependencies, I have tried to delete the cache and then using gradle build - nothing, it wouldn't download the jar files, only the pom files.
I have even tried to download the jars manually and put them in the correct directories in my local repository did not work.
Any help would be appreciated.
I don't think the Gradle cache can be transferred to another machine like this. I'm trying to create a plugin which can copy the dependencies from a configuration to a local directory for offline usage here but I've hit this issue where parent POM's and BOM's can't be accessed from the Gradle API's. I've got a failing test here demonstrating the usage of the plugin and the lack of parent POM support.
One of the suggestions on the issue is to try the IvyPot plugin. I haven't tried this myself but it might work for what you are attempting.
You might have proxy enabled, add proxy details in "gradle.properties" file like below:
systemProp.http.proxyHost=your.proxy.com
systemProp.http.proxyPort=XXXX
systemProp.http.proxyUser=user
systemProp.http.proxyPassword=password

Download all files under a groupId from Maven Repository through command or Java program

Our project is using Nexus Repository Manager to store all the jars.
Along with the jar I see that under a group there are other files like pom.xml, .md5, .sha1 file. I am in need of these files at our server startup.
Is there a way that I can download all the files under a particular group programatically using Java/Curl command/mvn dependency command at runtime?
Maven also uses local repository for caching. The default location is Default: ${user.home}/.m2/repository. You can check this setting in file settings.xml under [maven_dir]/conf/.
To update dependencies, use -U option. i.e. mvn clean install -U
Do not forget setting nexus repo inside pom.xml file http://maven.apache.org/pom.html#Repository
I could do it with the simple approach.
Club all the xmls into a JAR/ZIP file and upload that zip file under my groupId to the Maven Repository.
Then programatically use CURL/WGET to download the zip and unzip the contents of that zip file (using any available utility) at runtime.
Put all XMLs under a zip file.
Use mvn deploy to load this zip file to my Maven Nexus Repo.
Then Programatically during runtime, download the zip file using simple weburl call to that ZIP file.
Use ZIP4J or any other library to unzip the contents to my required output folder
Pick files from this server when needed during the flow.
Hope its helpful to someone somewhere sometime. :)

Download artifacts from local Maven Repository

Hey im new to maven and i was wondering if anyone knew if i had a bunch of files in a directory, can i make that directory a local repo for maven. the projects in there are not maven projects but would i be able to somehow downlaod those files onto another location using maven?
this is how the folder is organized:
patch
--new folder
----versions (multiple folders which contain zip files)
is there a way to getting the version folders and copying that to a different directory with a maven command like
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=org.hibernate:hibernate-entitymanager:3.4.0.GA:jar:sources -DoutputDirectory=/home/-Dmdep.useBaseVersion=true
You were very close to the correct solution - same plugin, different mojo:
$ mvn maven-dependency-plugin:copy-dependencies -DoutputDirectory=/path/to/output
This will dump all dependencies into the location of your choosing.
The -DstripVersion=true argument is useful if you want to have the jars by their canonical name without the version suffix (ie log4j.jar vs. log4j-1.2.17.jar).
Hope that helps.

Resources