Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding db2 jars to java webapp using maven

Tags:

maven

I'm trying to add the following db2 jars to my Java web application using Maven...

db2jcc_license_cu.jar  
db2jcc_javax.jar   
db2jcc.jar

I'm following the instructions posted in this post... Can I add jars to maven 2 build classpath without installing them?

I want to use the static in-project repository solution. So far I have...

  1. Created a folder in my root directory named lib. Inside this directory lives the three db2 jars.
  2. Added the following to my pom file...
 <repository>
        <id>lib</id>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>file://${project.basedir}/lib</url>    
 </repository> 
 </repositories>
<dependency> 
    <groupId>com.ibm.db2.jcc</groupId>
    <artifactId>db2jcc</artifactId>
    <version>3.8.47</version>
</dependency>
<dependency>
    <groupId>com.ibm.db2.jcc</groupId>
    <artifactId>db2jcc_license_cu</artifactId>
    <version>3.8.47</version>
</dependency>

But when I run a maven install I get ...

[WARNING] The POM for com.ibm.db2.jcc:db2jcc:jar:3.8.47 is missing, no dependency information available
[WARNING] The POM for com.ibm.db2.jcc:db2jcc_license_cu:jar:3.8.47 is missing, no dependency information available

I got the version of the Jars by running a...

java com.ibm.db2.jcc.DB2Jcc -version

Have I specified this version info corretly? Can anyone suggest what I am doing wrong?

like image 733
Richie Avatar asked Mar 13 '13 10:03

Richie


People also ask

Does maven download jar files?

2. Command Line. By default, Maven only downloads the actual JAR file of each dependency, not the sources and documentation files.

Where is the jars in Maven project?

Your Maven JAR is generated in your project's /target folder. You can deploy it manually into Liferay DXP's /deploy folder, or you can configure your project to deploy automatically to Liferay DXP by following the Deploying a Module Built with Maven to Liferay DXP tutorial.

What is db2jcc_license_cisuz jar?

The DB2 Universal JDBC Driver. db2jcc_license_cisuz.jar. The license file, db2jcc_license_cisuz. jar , contains licenses for Linux, Unix, Windows®, IBM System i®, and IBM System z. The IBM System z license is required in order to establish a JDBC connection to DB2 running on z/OS®.


2 Answers

The problem is that you didn't install the jars properly in your "project-maven-repository" (i.e. in the folder ${project.basedir}/lib)

Maven stores (when you do mvn install) the jar files in a maven repository. A maven repository have precise hierarchical structure. Here is a simplified vision of this structure:

  • the artifact groupId+artifactId define the first part of folder path (in the repository) where the artifact is stored.
  • the artifact version is the second part of the folder path
  • the artifact version is also a suffix to the artifact name
  • the artifactId is the artifact name
  • the packaging is the artifact extension (default is jar)

By default maven use a repository located under <USER_HOME>/.m2/repository

The solution you are trying to setup use another location for the repository : ${project.basedir}/lib and even if it is not the default repository location it is still a maven-repository and so maven is expecting to find the usual maven repository hierarchy under this location.

That's why you need to organize your ${project.basedir}/lib folder just like a maven repository. That's explained in this part of the referenced post:

Use Maven to install to project repo

Instead of creating this structure by hand I recommend to use a Maven plugin to install your jars as artifacts. So, to install an artifact to an in-project repository under repo folder execute:

mvn install:install-file -DlocalRepositoryPath=lib -DcreateChecksum=true -Dpackaging=jar -Dfile=[your-jar] -DgroupId=[...] -DartifactId=[...] -Dversion=[...]

If you'll choose this approach you'll be able to simplify the repository declaration in pom to:

<repository>
    <id>repo</id>
    <url>file://${project.basedir}/lib</url>
</repository>

So you need to do an mvn install to create the ${project.basedir}/lib hierarchy (you can do it by hand, but it's not recommended and error prone).

I your case, the commands to run will be like this: (assuming you put the jar in your HOME_DIR and run this command in your ${project.basedir})

mvn install:install-file -DlocalRepositoryPath=lib -DcreateChecksum=true -Dpackaging=jar -Dfile=<USER_HOME>/db2jcc_license_cu.jar -DgroupId=com.ibm.db2.jcc -DartifactId=db2jcc_license_cu -Dversion=3.8.47

What are the advantages of the approch you choose :

  • a developer with no maven setup will have the libraries available inside the project sources, under SCM system.
  • you can easily reference jars that aren't in a public maven repository without the need of something like artifactory or nexus

The drawbacks :

  • a quite complex folder structure under ${project.basedir}/lib looking very strange for someone not used to work with maven.
  • you will store the libraries under SCM (lot's of huge binary files)
like image 107
ben75 Avatar answered Nov 09 '22 00:11

ben75


Another solution would be to download those jars before hand and put them somewhere relatively to your project (like lib directory). Now just tell maven to use those jars. Here the groupId, artifactdId and version are JFYI since they won't be used to download anything.

The merit of this solution is that you won't have to build a maven repository.

<dependencies>
    ...      
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>licences</artifactId>
        <version>1.0</version> <!-- Adjust this properly -->
        <scope>system</scope>
        <systemPath>${basedir}/lib/db2jcc_license_cu.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc4</artifactId>
        <version>1.0</version> <!-- Adjust this properly -->
        <scope>system</scope>
        <systemPath>${basedir}/lib/db2jcc4.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc_javax</artifactId>
        <version>1.0</version> <!-- Adjust this properly -->
        <scope>system</scope>
        <systemPath>${basedir}/lib/db2jcc_javax.jar</systemPath>
    </dependency>
</dependencies>

Refer Link (Japanese): Mavenリポジトリで提供されていないサードパーティJarをどうするか

like image 29
nacho4d Avatar answered Nov 09 '22 01:11

nacho4d