3

I have a 3rd party dependency jar which need to be installed in order to build my project. I know this can be done using the install command, but what I need is to install it when I build my project. So no need to manually install the jar, is there a way to do it?

I found something like this to install plugins

<configuration>
<executable>mvn</executable>
<arguments>
    <argument>install:install-file</argument>
    <argument>-Dfile=${basedir}\src\main\resources\EVIPSoapServer.jar</argument>
    <argument>-DgroupId=com.company</argument>
    <argument>-DartifactId=EVIPSoapServer</argument>
    <argument>-Dversion=1.0.0</argument>
    <argument>-Dpackaging=jar</argument>
</arguments>

Is there a way to install dependencies?

Roy Justin
  • 653
  • 3
  • 10
  • 23
  • 1
    Is there any reason why you cannot install this dependency offline and then use it during your build? – Tim Biegeleisen Oct 16 '15 at 08:43
  • 1
    @TimBiegeleisen it can be done, but I'm asking this just for maintenance reason. So the manual process of installing dependencies can be skipped, when building the project all the jars will be automatically installed. Is it possible to do this in maven pom configurations? – Roy Justin Oct 16 '15 at 08:49
  • The [Maven documentation](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html) doesn't seem to be of any help here. – Tim Biegeleisen Oct 16 '15 at 08:57

2 Answers2

2

A better approach will be to create a multi module maven project, with your third party lib as one module and your project as another. In the root pom.xml, you can write the sequence of build and that will take care of the installing the third party jar before your project is installed.

Here is a tutorial for you Link 1

EDIT

From the comment, it seems like you only need the dependency jar to be available while installing. For this, the best approach would be to use a system scoped dependency, with the third party jar saved in a folder inside the maven project structure itself. Example is below. Read this link. This way, maven will not check whether the jar exists in local or remote maven repo.

    <dependency>
      <groupId>javax.sql</groupId>
      <artifactId>jdbc-stdext</artifactId>
      <version>2.0</version>
      <scope>system</scope>
      <systemPath>${your.path.here}</systemPath>
    </dependency>
aksappy
  • 3,400
  • 3
  • 23
  • 49
  • Well what I have is only the jar, is it possible to add jars as modules? – Roy Justin Oct 16 '15 at 08:54
  • 1
    Edited the answer. You can use a system scoped dependency. Ensure that the jar is inside your project itself. Somewhere inside lib. – aksappy Oct 16 '15 at 09:01
  • I tried this option, after this change my project compiles fine. But at run time its throwing exception, I'm getting NoClassDefFoundError. Am I doing anything wrong here? – Roy Justin Oct 19 '15 at 08:40
  • Your project is a standalone application I suppose? – aksappy Oct 19 '15 at 12:46
1

I was able to find a solution in this blog http://giallone.blogspot.com/2012/12/maven-install-missing-offline.html

Roy Justin
  • 653
  • 3
  • 10
  • 23