How do you upload artifacts in nexus via the file system - maven

I am running nexus 2.9.1.02 to host artifacts for maven builds. I would like to load artifacts via the file system. I do not want to use the web UI. Instead, just putting the folders with required pom and jar files in the sonatype-work/nexus/storage folder.
After loading the files into the file system, the artifacts show up in the "browse storage" tab. However, they do not show up in the "browse index" tab and Maven can not download them.
Is it possible to load artifacts via the file system only? How do you sync the file system to the repo database/indexing?
Thanks,
Nathan

There's a way to do this that should be repository agnostic. Use the mvn deploy:deploy-file plugin. Here's an example:
mvn deploy:deploy-file
-DrepositoryId=repoId
-Durl=repoUrl
-Dfile=pathToFile
-DgroupId=groupId
-DartifactId=artifactId
-Dversion=versionNumber
-DgeneratePom=true

Yes, you can place artifacts directly into local storage. See here for tasks you will need to run after doing this:
https://support.sonatype.com/entries/38605563-Can-I-directly-update-artifacts-in-Nexus-local-storage-on-disk-

Related

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

Maven deploy plugin keep the file name when uploading

I am using maven deploy plugin to upload a file inside bamboo deployment stage. I am uploading the file without pom file. When I upload the file to Nexus, the file name is changing completely. Its appending with project name, version number and build number. I want to keep the filename as it is. Any one know how to do this?
mvn deploy:deploy-file
-Dfile=${bamboo.artifacts.path.artifactFile}
-Dpackaging=cba
-url=https://nexus.internal.organisation.com/content/repositories/snapshots/
-DrepositoryId=snapshots
-DgroupId=com.organisation.art
-DartifactId=myproject
-Dversion=0.0.1-SNAPSHOT
A maven managed repository, such as that provided by Nexus et al, is set up in a way that is intended for deployed products to be returned to a maven build process that has them declared as dependencies.
It is not intended to be a generic file server.
If you have Nexus 3.0 or newer then you have access to so called "raw" repositories that you can set up any way you like.
However you would not use mvn deploy:deploy-file to add files to it. Instead you would follow the instructions in Uploading Files to Hosted Raw Repositories.

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.

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.

Maven without Internet connection

I'm new to maven project.
I'm changing an ant project to maven project.
To install the 3rd party jar's in maven local repository, I used install command.
Its trying to download the resource jar.pom.
I don't have download access in my organization so the build failed for installtion.
After request i got the resouce jar and clean jar in my desktop(also i can get other necessary jar).
How to make maven to use these jar for the process and how to install the jar in local repository without internet acess.
I downloaded the jar and placed in local repository but it couldn't point the path and use those jars.
please let me know what steps i have follow to run maven install and other commands to build the project without internet access.
where should i placed the jar which i have downloaded by external way.
Please guide me for building and deploying the project.
Thanks in advance.
http://maven.40175.n5.nabble.com/Maven-installation-and-using-in-project-without-Internet-conncetion-tp4564443p4564443.html.
http://www.coderanch.com/t/544641/Jobs-Offered/careers/Maven-installation-project-without-Internet#2471141
I've posted same question in these link
You need an internet connection. Maven isn't initially self-sufficient. It needs to download a bunch of plugins along with their dependencies and the dependencies of your own project. And this really depends on what sort of settings you have for your projects. One set up will require one set of dependencies, another - a whole different one. You can't download artifacts from the Maven Central manually and then install them locally one by one. Simply put, that sounds stupid.
I understand that you're coming from the Ant world where Ant has everything it needs on the local file system. However, Maven relies on the fact that it will have a central repository (either Maven Central, or your own repository - Nexus, Artifactory, etc.) from which to download the plugins and dependencies it needs. There is no point in you migrating to Maven, unless you'll be allowed access to the Central Maven Repository.
Yes, indeed, you can run Maven offline and you can have Maven produce a local repository for you to use when you are in offline mode. However, what you're trying to do is against Maven's principles.
If your company won't allow access to Maven Central, just stick to Ant. Your effort will be a waste of your company's and, ultimately, your own time.
In fact the maven strenght is mainly in the internet accessible repositories and automatic dependency management. But it's possible to use this tool to build your project if you have all dependencies required for your project in your local repository. Then you may use -o option for offline mode and maven will not try to download updated artefact versions.
To get the artifacts into you local repository you have several options:
1) connect to the internet once and mvn build the project (this will download all required dependencies)
2) install dependencies as jar to the local repository manualy (using appropriate mvn command)
I think the questioner is looking for -o or --offline option for mvn. This is a command line option and can be provided while executing.
I think you can setup your repo correctly and execute the mvn goals once when you are connected to internet and use the -o option for later executions .
Hope this helps.
~Abhay
You can configure maven to run in offline mode. Add this entry to your settings.xml
<offline>true</offline>
See here for further information:
http://maven.apache.org/settings.html
Before you can use offline mode, you have to install all necessary third party jars to your local maven repository.
mvn install:install-file
-Dfile=filename.jar
-DgroupId=com.stackoverflow
-DartifactId=artifact
-Dversion=1.0.0
-Dpackaging=jar
-DcreateChecksum=true
-DgeneratePom=true
It's much easier to get those jars in your local repository using an internet connection and online mode.
It's possible to install these resource jars in your local maven repo using install-file. This will make the available to the build. You'll have to do this for each individually, but once that's done you won't have to do anything special.
To be clear, maven puts everything in your local repository, both the jar you're building with this project and the various library jars. Because your system cannot be connected to the internet to maven can populate the local repo with your libraries, you'll have to use this manual approach.
Edit: You should be able to run install-file anywhere. When you do, you'll need to provide the groupId, artifactId, version, and packaging using the command line options. If you already have a POM file for the library, you can provide that instead via -DpomFile=your-pom.xml.
This question has some useful info: How to manually install an artifact in Maven 2?

Resources