1

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?

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
  • 2
    You can simply build a project which automatically downloads the needed artifacts and put them into the local cache $HOME/.m2/repository ...you don't need to install them manually... – khmarbaise Oct 08 '19 at 09:44
  • but then I have to manually put it as dependency in the `pom.xml`? `npm install` also does it for me. It adds it as dependency in the `package.json`. – BuZZ-dEE Oct 08 '19 at 09:50
  • @BuZZ-dEE Yes, but why is it easier to write `npm install rxjs` than adding that entry to the `pom.xml`? In either case, you need to know what you add. – J Fabian Meier Oct 08 '19 at 10:50
  • @JFMeier I ask you the opposite. ;) A lot of package management systems allow command line installation from a remote repository. Why not Maven? In `npm` I could do both, install the dependency through the commandline or I can put it in the `package.json`. – BuZZ-dEE Oct 08 '19 at 11:25
  • This does not work in maven, maven artifacts are identified by a groupId and an artifactId, not just a name. Dependencies can come from any number of repositories, not just the maven central repository. So whatever you do you'd have to go to a site such as mvncentral.com and figure out the groupId/artifactId combination... you might as well copy-paste the XML snippet you will find there to put the dependency in your pom. – Gimby Oct 08 '19 at 12:10
  • Probably because most people never missed it. You put the dependency in the POM and that's it. In Maven, you usually don't care whether the dependency is (already) locally available or not. You let Maven manage that. – J Fabian Meier Oct 08 '19 at 12:10
  • The pom.xml describes what kind of dependencies you have and also which is being handled by maven which also means it's downloaded automatically if needed. no manual handling needed...makes life easier... – khmarbaise Oct 08 '19 at 12:21
  • (whoops: mvncentral.com = mvnrepository.com in my previous comment...) – Gimby Oct 09 '19 at 07:50

1 Answers1

1

Unfortunately, there are no such commands.

One option is through a shell scripts or stream editors (e.g. sed).

Dmitry Rakovets
  • 557
  • 1
  • 6
  • 15