Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install File Using POM instead of commandline

Tags:

maven

I'm currently using:

mvn install:install-file -Dfile={path/to/my/legacy.jar} -DgroupId=horrible -DartifactId=legacy.jar -Dversion=1.2.3 -Dpackaging=jar 

to import some old legacy jars into my repo. This has worked fine and is the recommended approach. It seems as though this could be done with a POM instead of at the commandline + script that I'm using now. I think it's cleaner to have:

mvn install:install-file 

and let my repo store the version details rather than store this information in a non-maven script (which is odd for maven). I tried to expose these -D settings via the settings tag but that didn't work. Has any one else tried this and got it to work?

like image 500
reccles Avatar asked Mar 27 '12 15:03

reccles


People also ask

What does mvn install file do?

The mvn install command runs the install plugin used in the install phase to add artifact(s) to the local repository. The Install Plugin uses the information in the POM (groupId, artifactId, version) to determine the proper location of the artifact within the local repository.

What is Maven POM file?

What is a POM? A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

What is Maven install command?

The short answer. Apache Maven is a popular build tool, that takes your project's Java source code, compiles it, tests it and converts it into an executable Java program: either a . jar or a . war file. mvn clean install is the command to do just that.

Where does Maven install dependencies?

The Local Repository Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named . m2.


1 Answers

Okay, answering my own question :P. You can do this by defining properties, I originally assumed the groupId etc were auto exported as properties but they are not.

<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   <modelVersion>4.0.0</modelVersion>   <groupId>com.whatever</groupId>   <artifactId>Stuff</artifactId>   <version>1.2.3</version>    <description>   Description of why this horrible jar exists.   </description>    <properties>      <groupId>${project.groupId}</groupId>     <artifactId>${project.artifactId}</artifactId>     <version>${project.version}</version>     <packaging>${project.packaging}</packaging>     <file>mylegacy.jar</file>   </properties>    <build>     <plugins>       <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-install-plugin</artifactId>         <executions>           <execution>             <phase>install</phase>             <goals>               <goal>install-file</goal>             </goals>           </execution>         </executions>       </plugin>     </plugins>   </build>  </project> 

You can now install files using:

mvn install 

and this pom.xml. I have tested this with maven 3 and not 2.

For multiple files also see Maven POM file for installing multiple 3rd party commercial libraries

like image 158
reccles Avatar answered Sep 27 '22 17:09

reccles