I'm searching for a Maven CLI command to install a Maven artifact (e.g. jar library) from a remote Maven repository. I don't want to manually download the artifact first, so that I can install it. I'm looking for a command like npm install rxjs, which automatically downloads rxjs and installs it as a dependeny to my project.
Is there an equivalent command available for Maven?
Unfortunately, there are no such commands.
One option is through a shell scripts or stream editors (e.g. sed).
Related
I am building a JavaFX project using NetBeans. When I build the project, Maven builds and installs the project JAR to my local repository.
I don't want to install my project to local repository, how do I stop this?
look at Maven default lifecycles, maybe mvn package is a better option
I want to keep custom jar in local repository.Maven is already installed in eclipse.But coming to the command prompt it is showing as "The program 'mvn' is currently not installed. You can install it by typing:
sudo apt install maven"
If i install the maven and keep that jar in local repository,will it reflect eclipse pom?
You need to install maven on your system as suggested.
Now in eclipse go to Window -> Prefrences -> Maven -> installations and add that maven there.
Then install your custom jar to maven as suggested here.
eclipse brings its own maven implementation.
If you want to run maven from command line you need to install it explicitly.
I need to release our Maven build Java project to an remote QA team. For this I would like to download all the dependencies, and send them so they do not need to download them.
Currently all dependencies are defined in the pom.xml file, and we use either mvn install or mvn package to build the project. Some of the project members use uber jars, others use jars + dependencies to do execution.
What would be the easiest way to pre-package the dependent jar files so that there is no download from the internet, and does not change our current build process too much?
A possible solution would be to purge your local repository, tell Maven to download every dependencies and plugin dependencies of your project and make a ZIP of that.
To purge your local repository, you can simply delete the folder {user.home}/.m2/repository. Then, you can use the dependency:go-offline goal:
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
mvn dependency:go-offline
This will download everything that your project depends on and will make sure that on a later build, nothing will be downloaded.
Then, you can simply make a ZIP of {user.home}/.m2/repository and send that to your Q/A team. They will need to unzip it inside their own {user.home}/.m2/repository to be able to build the project.
Offline Package deploy
Your requirement can be accomplished by creating a stand alone jar file with full dependencies. You can port it anywhere please refer https://stackoverflow.com/a/35359756/5678086
Build a full dependency JAR file as said in the answer
Copy the JAR to the destination machine you want
Run the below command from there
mvn install:install-file -Dfile=<path-to-file>
This will install the dependecies in the maven repository of the destination machine. This is fully offline
Theoretically if you know which maven commands you'll use (package, install, etc.) you could clear out your ~/.m2/repository folder, run those commands once on somebody's dev box, then distribute the repository folder. You can run maven -o install etc. to have it not give annoying warnings. This might be a slightly smaller distro than the go-offline answer.
When i Use option of sts "install or deploy an artifcator in eclipse".it works properly but when i do it manually by using mvn install command and change the version in pom.xml.it deploys artifactory to local repository. but when i refered it in some other project its symbol is different from others.
in above image, OES-ClientCore:24.0.9 is deployed using maven command and i ma refering it in some other project.
and also not working properly.so just tell me the difference of option of sts for "install or deploy an artifcator in eclipse" and manually using command mvn install
mvn install will install the artifact in your local maven repository.
Use mvn deploy to deploy it to a remote repository to share it with other developers and projects
See also:
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
I have maven eclipse plugin and I want to use a jar file in my project that is not supported in maven so I found out I have to do something like this :
mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar
So I have to install maven to issue that command but won't that cause redundancy with maven plugin ?
You can install multiple different versions of maven, and configure m2eclipse to use a specific instance, see the setting under Window > Preferences > Maven > Installations.
Managing multiple different versions on the command line is controlled by the PATH environment variable, you would normally define an environment variable M2_HOME which specifies the home directory of the version that you are currently using, and then add $M2_HOME/bin or %M2_HOME%\bin to your path environment variable.
It is no problem if you have both maven and eclipse maven plugin installed. I only use eclipse maven plugin for its pom.xml file editor. I do all other operations about maven through the command line.
Besides, the plugin (m2eclipse) I used, sometimes give strange dependency errors although everything is fine. Because when I run a "mvn install" for the project, it is built successfully. So, I think using maven itself is more reliable.