使用Maven将db2 jar添加到Java Webapp [英] Adding db2 jars to java webapp using maven

查看:120
本文介绍了使用Maven将db2 jar添加到Java Webapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Maven将以下db2 jar添加到Java Web应用程序中...

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

我正在按照此帖子中发布的说明进行操作... 我可以将jar添加到Maven 2构建中吗没有安装它们的classpath?

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. 在我的根目录lib中创建了一个文件夹.在这个里面 目录中包含三个db2 jar.
  2. 将以下内容添加到我的pom文件中...
  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>

但是当我运行Maven安装时,我得到了...

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

我通过运行...获得了Jars的版本.

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

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

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

我是否正确指定了此版本信息?谁能暗示我做错了什么?

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

推荐答案

问题是您没有在"project-maven-repository"(即文件夹${project.basedir}/lib)中正确安装jar.

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(在执行mvn install时)将jar文件存储在maven存储库中. Maven存储库具有精确的层次结构.这是此结构的简化视图:

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:

  • 工件groupId + artifactId定义存储工件的文件夹路径的第一部分(在存储库中).
  • 工件version是文件夹路径的第二部分
  • 工件version也是工件名称的后缀
  • artifactId是工件名称
  • 包装是工件扩展名(默认为jar)
  • 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)

默认情况下,maven使用位于<USER_HOME>/.m2/repository

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

您尝试设置的解决方案使用其他位置的存储库:${project.basedir}/lib,即使它不是默认的存储库位置,它仍然是 maven-repository ,因此maven希望在该位置下找到常规的Maven存储库层次结构.

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.

这就是为什么您需要像Maven存储库一样组织${project.basedir}/lib文件夹的原因.在的这一部分中对此进行了解释帖子:

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:

使用Maven安装到项目存储库

我建议不要使用手工创建此结构,而是使用Maven插件将jar安装为工件.因此,要将工件安装到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=[...]

如果您选择这种方法,则可以将pom中的存储库声明简化为:

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>

因此,您需要执行mvn install来创建${project.basedir}/lib层次结构(可以手动执行,但是不建议这样做,并且容易出错).

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).

在您的情况下,要运行的命令将如下所示:(假设您将jar放在HOME_DIR中,并在${project.basedir}中运行此命令)

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 :

  • 没有Maven设置的开发人员将在SCM系统下在项目源内部提供库.
  • 您可以轻松引用不在公共Maven存储库中的jar,而无需类似 artifactory的jar 关系

缺点:

  • ${project.basedir}/lib下一个非常复杂的文件夹结构,对于不习惯使用maven的人来说非常奇怪.
  • 您将把库存储在SCM(大量巨大的二进制文件)下
  • 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)

这篇关于使用Maven将db2 jar添加到Java Webapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆