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

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. :)

Related

How to deploy artefacts to Artifactory using Maven without a POM

I need to send a jar file to artifactory maven repo. I don't want to use pom.xml. I have configured settings.xml with details of artifactory. What would be the full commandline command to send jar to artifactory. I need maven-matadata.xml to be generated so that with every upload I can fetch tag in .xml file.
And also what would be default location of settings.xml? I see there are two locations. One is withing "apache-maven" folder and other one is inside .m2 folder under user's home directory.
Thank you
After using double quotes in mvn command (as I am executing it in powershell), it is working fine.

How to deploy a zip contains text files to remote repository from maven project

Is there any way to deploy a zip file which contains few text files to the remote repository from a maven project.
I tried to use maven-deploy plugin with goal as deploy-file, but the zip does not contain any pom.xml file.
Can anyone please share the way to upload a zip to a remote repository. Thanks in advance.

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.

maven - how to deploy non-jar files

In my project I have many modules.
One of the modules requires a jar file to be deployed to the repository which it does fine.
The others involve every other kind of file: zip, kar etc.
I can see the zip get uploaded if I look for it via the terminal but if I browse Archiva it is not there.
The kar file, for example, does not need to be built but it's being worked on and is currently manually uploaded to the repository (Archiva). This is not desirable.
Each module has a POM and each POM uploads empty jar files to Archiva when it is built (with Jenkins). How can I avoid that? And can I copy files to Archiva without them having to be built into a jar file?
You can also give a try to "maven-deploy-plugin"
Invoke a maven target in jenkins with this plugin and provide the suitable parameters.
You would also need the repository to be added in you settings.xml if your repository requires login credentials and then use the ID, you mentioned in settings.xml, in the maven target.
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file
-Durl=<artifact-repo URL>
-Dfile=<name of the file>
-DgroupId=<Group Id>
-DartifactId=<Artifact Id>
-Dversion=<VERSION>
-Dpackaging=<packaging Type>
-DrepositoryId=<ID as mentioned in settings.xml>
Hope this may be of some help.

Deploy jar files to Archiva manually

I have a lot of jar files in my local hard drive and I want to use them as a repository so that my internet connection requirement can be removed.
I installed Archiva but I don't know how can I deploy the jar files to Archiva. there is a UI form which does this task but deploying huge amount of jar files by hand is not easy and waste a lot of time.
How can I use my local jar files as a repository so that I can use Maven(or Ivy) to manage dependencies?
You can upload them with mvn deploy:deploy-file, which you could use in a script for a bulk upload (discussed here, and here's an example script).
As an alternative, if you want to use those local files directly, you can copy them into the storage location of an Archiva repository. From this thread:
One way to put all your local .m2 repository content is to copy from
~/.m2/repository to
${archiva-install-dir}/data/repository/${managed-repository-name}/
...
Once the copy is done, you can force Archiva d/b scan on the managed
repository.

Resources