6

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?

Community
  • 1
  • 1
Richie
  • 4,989
  • 24
  • 90
  • 177
  • can describe more precisely the folder hierarchy (if any) you have under ${project.basedir}/lib ? – ben75 Mar 13 '13 at 11:14
  • Hi. I have no folder hierarchy under lib except the jars. The instructions in the post above say something about x.y.z . That bit confused me. – Richie Mar 13 '13 at 20:43

3 Answers3

11

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)
Community
  • 1
  • 1
ben75
  • 29,217
  • 10
  • 88
  • 134
3

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をどうするか

nacho4d
  • 43,720
  • 45
  • 157
  • 240
1

I guess these jars do not have a pom.xml. Hence the warning. If the jars get packaged and the application works, then I guess you do not have a problem.

ben75
  • 29,217
  • 10
  • 88
  • 134
Raghuram
  • 51,854
  • 11
  • 110
  • 122