如何将外部jar添加到Maven

如何将外部jar添加到Maven

本文介绍了如何将外部jar添加到Maven Webapp项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring roo项目(基本上是一个maven项目).我想将Dropbox SDK添加到项目中,问题是它不在Maven中.我添加了以下文件

I have a Spring roo project (basically a maven project). I want to add dropbox sdk to the project, problem is it's not in maven. I added the following files

    <dependency>
        <groupId>com.dropbox</groupId>
        <artifactId>dropbox-sdk</artifactId>
        <version>1.3.1</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/dropbox-java-sdk-1.3.1.jar</systemPath>
    </dependency>

它解决了编译错误,但是当我运行项目时,在Spring Tool Suite中,jar文件未添加到war lib文件夹中.如何使Maven将我的外部jar文件添加到war lib文件夹中?

It solved the compile error, but when i run the project, in Spring Tool Suite, the jar files are not added to war lib folder. How do I make maven add my external jar files to my the war lib folder?

我不想在jar中安装jar,因为我必须将其安装在使用该项目的所有机器中

I don't want to install the jar in maven since, I have to install it in all the machines that uses the project

推荐答案

我终于找到了一个简洁的解决方案,它易于实现.您在Java项目中添加了一个项目内存储库,并在pom中链接到它.

I finally found a neat solution, which is a lot easier to implement. You add an in-project repository inside the java project and link to it in the pom.

您可以像这样在maven中添加一个项目内存储库:

You add an in-project repository in maven like this:

<repository>
    <id>in-project</id>
        <name>In Project Repo</name>
        <url>file://${project.basedir}/libs</url>
</repository>

然后在项目的根文件夹中创建一个类似于以下内容的文件夹结构

Then create a folder structure in the root folder of your project that looks something like this

/groupId/artifactId/version/artifactId-version.jar

并像通常一样添加依赖项.

and add the dependency as you would normally do.

这种方法所需的代码和工作量最少,并且如果该库曾经添加到Maven存储库中,则您始终可以删除项目中的存储库.

This approach has the least amount of code and work required, and if that library ever gets add into a maven repository you can always remove your in-project repository.

http://bit.ly/OGVHSN

这篇关于如何将外部jar添加到Maven Webapp项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:26