A circumstance may arise whereby a jar file is required for a project which is not in maven. This has happened recently in a project I worked on which requires a Websphere MQ jar, which is not available via maven.
The jar can be included into the project as follows - the main steps are
- Deploy the jar to a file location within the project
- Use the maven-install-plugin to load the jar from the file system rather than from the maven repo
- Dependencies are defined in pom.xml as normal (see version number below)
Deploy jar file to project location
The jar file needs to be deployed to a repo location - maven has a command to do this as follows ;
mvn install:install-file -Dfile=<jar_file_to_deploy> -DgroupId=<groupid> -DartifactId=<?artifactid?> -Dversion=<version> -Dpackaging=jar -DlocalRepositoryPath=<deployment_location>
E.g. for the mq.jar, which is group id com.ibm, artifact id mq use the following command
mvn install:install-file -Dfile=C:\peter\mqjms-9.0.jar -DgroupId=com.ibm -DartifactId=mq -Dversion=9.0 -Dpackaging=jar -DlocalRepositoryPath=E:\Repos\Git\mqbridge\repo
Note the version - this is set artificially high to ensure hat it doesn not conflict with any pre-existing maven version
maven-install-plugin
The pom.xml file needs to know that it should load the jar file from the file store, rather than from the maven repository. This can be achieved as shown below.
Note that multiple executions are used for multiple files. It should be noted that the files are loaded during the install-file phase of the build - to ensure that this goal is implemented, the project should be built with the 'clean' parameter (e.g. mvn clean install)
<plugin> <artifactId>maven-install-plugin</artifactId> <executions> <execution> <id>install-mq</id> <phase>process-resources</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>com.ibm</groupId> <artifactId>mq</artifactId> <version>9.0</version> <packaging>jar</packaging> <file>${project.basedir}/repo/com/ibm/mq/9.0/mq-9.0.jar</file> </configuration> </execution> <execution> <id>install-mqjms</id> <phase>process-resources</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>com.ibm</groupId> <artifactId>mqjms</artifactId> <version>9.0</version> <packaging>jar</packaging> <file>${project.basedir}/repo/com/ibm/mqjms/9.0/mqjms-9.0.jar</file> </configuration> </execution> </executions> </plugin>
Define dependencies
Dependencies are defined as normal - the version number should match the version used when the jar file was deployed to the file system (see above).
E.g.
<dependency> <groupId>com.ibm</groupId> <artifactId>mq</artifactId> <version>9.0</version> </dependency> <dependency> <groupId>com.ibm</groupId> <artifactId>mqjms</artifactId> <version>9.0</version> </dependency>