Search code examples
javaeclipsemavenm2eclipse

How to add 3rd party JARs to Maven project


My area of expertise is not Java. I develop in other languages on other platforms.

Right now I'm developing a series of Java servlets for a project. The servlets are to run on a CentOS server running FileNetP8.

I actually got all of the planned items finished and running.

Now when I am trying to add a few more services, the library I came across is available via Maven. I have no idea what Maven is. Read up on it today. Created a test project to try it out.

My development environment is Eclipse Photon on Windows 10.

Now my problem is I can't figure out how to add the Filenet JARs to the project. I can't upload them to some Maven repo. Searching the Web says to add them to the local repo, but I don't understand how to do that to the Local repo in Eclipse's builtin Maven.

I think that the JARs don't need to be packaged within the deployment WAR because the app will be deployed to the Websphere server that runs Filenet so they should be available on it. Should I add them as external JAR references to get the project to compile?


Solution

  • I provide below the following approaches to check based upon your suitability.

    Approach-1: Install manually

    If you have only 1 jar file, execute the following command by replacing as per your requirements.

    mvn install:install-file \
       -Dfile=<file path location> \
       -DgroupId=<your own custom group id> \
       -DartifactId=<your own custom artifact id> \
       -Dversion=<some version number> \
       -Dpackaging=jar \
       -DgeneratePom=true
    

    Once it is done, use the following in your project pom.xml in the dependency section.

    <dependency>
        <groupId>your own custom group id</groupId>
        <artifactId>your own custom artifact id</artifactId>
        <version>some version number</version>
    </dependency>
    

    The downside of the above approach is, only you can use it as it installs in your .m2 directory. For other developers, they have to follow the same approach. It is not a suggested approach.

    Approach-2: Manually add the location of jar file

    Add the following dependency in pom.xml

    <dependency>
        <groupId>some.group.id</groupId>
        <artifactId>some.artifat.id</artifactId>
        <version>some.version.no</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/yourActualJarFileName.jar</systemPath>
    </dependency>
    

    The downside of the above approach is, you have to put all the jar files in a directory and you have to provide the path. All the jar files should be part of your project, it means all the jar file should be put in source code repository. Although it servers the purposes, still it is not a good approach. If you got a newer/higher version of jar file, again you have to put it inside your lib directory. It means you have manage all the old and new versions of jar files.

    Best Approach

    Maintain Nexus or Artifactory, or any artifactory management system in the organisation and put all the jar files and provide the definition of your custom jar file. It will provide you pom definition. Based upon this, you have to add the dependencies in your project pom.xml. Here you can maintain n number version of your custom jar files.