2

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?

Hussain Akbar
  • 646
  • 8
  • 25
  • Are the filenet JARs actually required for compiling? If yes, they are scope-compile dependencies. You can bring jars along with the project locally through an install step. If the filenet JARS are not required for compiling, and are provided by Websphere, then a scope-provided is sufficient. – Compass May 28 '19 at 16:58
  • If the dependencies are external to your project you should see if they are available in Maven Central. They will not be available in a central repository if they are created internally for your project. In that case you need to mvn deploy them to either your local .m2 or an internal Maven repository. – duffymo May 28 '19 at 17:13
  • As per https://developer.ibm.com/answers/questions/259449/does-it-exist-an-ibm-filenet-p8-platform-maven-rep/ these dependencies are not available via Maven. When FileNet is installed, they can be downloaded from it https://i.stack.imgur.com/yXqrt.png Yes, they are needed to compile. – Hussain Akbar May 29 '19 at 06:03
  • Here we go!! https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html – Pratik Ambani May 29 '19 at 08:11
  • Thank you for the reply. That page shows how it's done when Maven is installed. As I mentioned, I am using the Maven which is built into Eclipse. – Hussain Akbar May 29 '19 at 12:34

4 Answers4

3

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.

Sambit
  • 7,625
  • 7
  • 34
  • 65
  • Approach-2 seems more likely to work. Should the files be in /libs or in /WebContent/Web-Inf/libs? – Hussain Akbar May 29 '19 at 12:38
  • As mentioned, you can create a directory called libs inside the root project folder. – Sambit May 29 '19 at 13:54
  • Approach-2 didn't work. On running clean install, I get warnings that dependencies should not point to system path as jar will be unresolvable by dependent projects. Didn't seem like the issue. But then, compilation fails that the import fails as the jar cannot be found. Yes, I placed the jars in /libs in the root of the project. – Hussain Akbar May 30 '19 at 05:31
  • Eureka! Works now. I hadn't placed one of the JAR's using this method as it could be found in Maven Central. Turns out that the two libs have the same name but are different to each other. Got a successful build now. Thanks. – Hussain Akbar May 30 '19 at 06:34
  • Great, hope information was useful to you. – Sambit May 30 '19 at 06:39
  • Spoke to soon. Upon deployment, I am getting a NoClassDefFoundError message. Looks like the JAR didn't get included in the WAR file. Shall open both versions and see... – Hussain Akbar May 31 '19 at 06:31
  • Looked in the WAR files. In a non-Maven project, the JAR's get copied into WEB-INF/lib. In the Maven project, all other JAR's are there, but these ones aren't. hmm... – Hussain Akbar Jun 03 '19 at 09:50
2

Seeing as every answer involves maven i'll try to provide a different and somewhat old school approach. You could always import your jars directly into your project by right clicking on it -> properties -> Add Jars. Apply when done and Voilà. This is far easier than understanding the complexity of maven.

JPG
  • 378
  • 4
  • 11
  • I tried that. Now the missing JAR red underlines disappear in the source and clicking on Build works. However, there's no option to export to WAR. Another page said to right-click on the project and select Maven->Maven Build. Doing that gives me compile errors that the JARs are missing.. – Hussain Akbar May 29 '19 at 12:36
  • You could always maven clean > install your project to build the WAR of your project. I'm not sure if what you did earlier will work though since the JAR is not a maven dependency. – JPG May 29 '19 at 13:00
1

Dependencies need to be added in pom.xml under dependencies tag. Maven will download the specified jars from maven central repository for the first time, and it will be saved in your local repo. If the dependencies are not available in central repo and if they have their own repo, you to need specify it in the repositories tag.

<repositories>
    <repository>
         <id>repo-id</id>
         <name>repo-name</name>
         <url>http://repourl</url>
    </repository>
</repositories>

Any change in the pom.xml, maven will automatically download it.

<dependencies>
   <dependency>
      <groupId>dependency-id</groupId>
      <artifactId>artifactid</artifactId>
      <version>1</version>
   </dependency>
</dependencies>
0

If the jars are available in Maven Central repo then all you hvae to do is add dependency under dependencies section in your pom.xml file. Set the scope as required, like you said jars don't needed to be packaged in WAR file as they might be available on server then you can set scope to provided.

<dependency>
  <groupId>groud-id</groupId>
  <artifactId>artifact-id</artifactId>
  <version>version-numbe</version>
  <scope>scope</scope>
</dependency>

If jars are not available in central repo and you want to install them on your local repo then below command should help you. More information here.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Sandeep Kumar
  • 13,799
  • 21
  • 74
  • 110