Download artifacts from local Maven Repository - maven

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.

Related

Deploy mutliple artifacts to the same folder using maven

Currently we have one main pom file which builds the code for multiple modules using the module tag. When I use the "mvn clean package deploy" command (which references the main pom file and performs these actions fro all other modules), the packaged file(war/jar) for each module is placed in it's respective target directory. Since there are different modules and they have their own respective group-id,artifact-id etc. the packaged files are spread across different folders.
My applications consists of all of these modules and I need all the packaged files under one single folder. Till now we have used an ant script to copy the relevant files from all of these modules to a single folder.
Apart from copying the files/aggregating all the packaged files and then uploading it as part of deploy:deploy-file is there any way I can deploy all the files to the same folder?
No, this is not possible.
The directory structure in Artifactory is always of the form
org/something/artifact/1.2.3/artifact-1.2.3.jar
assuming groupId org.something, artifactId artifact and version 1.2.3.
This structure cannot be changed.

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

Exporting Maven Archetype from Local Repository

I have a Maven archetype that I created myself from one of my projects and installed in my own local Maven repository. From Eclipse I am able to create new projects using this archetype and I obviously have access to the archetype's "installed" files (the ones that are placed in the repository after the install).
The problem is that now I want to share the archetype to a colleague, but after I created it and installed it to my local repository, I deleted the "installer" files (the ones that are generated in the generated-sources/archetype folder of my source project), so now I only have the archetype installed in my repository and I don't know how to export it in order to share it with someone else.
I could create a new archetype, but I put so much effort and spent several hours in doing that in the first place, so I would like to find out exporting the current archetype is possible, and if so, how can I do it?
EDIT
Asked in a different way, can I take the "installed" files from my local repository and put them in other repository, and have Maven recognize them as an Archetype?
What we ended up doing was to zip the repository archetype folder and send it to my colleague, who then performed these steps:
Unzip the archetype folder file to the root of his local Maven repository.
Execute the command ´mvn archetype:crawl´.
That was it. He was able to use the archetype for creating new projects.

Copying jar from local Maven repository

I'm working on a sort of deployment script for a Java project using Python/shell. The script currently can copy jars either from a Sonatype Nexus repository or from the project's target folder. The remote/Nexus setup seems all good, but I'm interested in instead copying from the local maven repository because allows me to always know the location of the jar regardless of where the project is installed.
I guess my question is: Am I overlooking anything by just copying the first jar from the folder ~/.m2/repository/{groupid}/{artifactid}/{version}? Or is this totally a good way to go about this?
If the groupId consists of more than one part, for example org.apache.httpcomponents , then the folder structure reflects this: org/apache/httpcomponents/...
There may exist more than one jar file inside the version directory.

How to access the folder of the downloaded artifact using properties?

I have an artifact in Nexus containing a ZIP file, let's say
<groupId>com.ddd.tools</groupId>
<artifactId>mytool</artifactId>
<version>2.1.0</version>
<classifier>bin</classifier>
<type>zip</type>
Now, I have another Maven project which depends on the above artifact so that I declare the above in the project's dependencies.
In the current project's workspace I download and unzip the content of the above ZIP archive using the command
mvn clean dependency:unpack-dependencies
which unzips the content to the folder ${project.build.directory}/dependency/mytool-2.1.0.
My question is how can I access the subfolder mytool-2.1.0 using Maven properties or any other variables?
Today it's version 2.1.0 but tomorrow it could be any other. In either case I'd like to have a method that works independent of it.
The background of the question is that in my build process I download several artifacts with ZIP files from Nexus, unzip them and then I want to copy them to other destinations which use other folder names.

Resources