Adding db2 jars to java webapp using maven
maven
Solution
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)
Problem
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... - Created a folder in my root directory named lib. Inside this directory lives the three db2 jars. - 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?