我想使用Maven从我的libs项目文件夹中加载所有JAR [英] I want to load all JARs from my libs project folder with Maven
问题描述
我有一个使用Maven的Java项目.在我的项目中,我有一个名为libs
的文件夹,其中包含无法从Internet/外部存储库加载的所有JAR.
I have a Java project using Maven. In my project I have a folder called libs
that contains all the JARs that I can't load from internet/external repository.
我的问题是如何指定Maven在打包,构建等过程中包括那些JAR?
My issue is how to specify to Maven to include those JARs during packaging, building etc.?
Maven的新手,很抱歉,这是一个愚蠢的问题.
New to Maven, sorry if it is a stupid question.
我有一个自动工具,它将在我的Git上查找我的pom.xml
来构建&在不同的环境中部署我的项目.因此,如建议在此处将无济于事,因为它只能在我的PC上运行.如果我在JAR文件夹中添加libs
文件夹,则无论我在哪里,它都可以使用.
EDIT : I have an automatic tool that will look up at my pom.xml
on my Git to build & deploy my project on different environments. So adding it in local Maven repo, as suggested here will not help since it will work only on my PC. If I add a libs
folder with my JARs it will work wherever I am.
如果不清楚或误解,请在评论中问我.
Ask me in comments if it's not clear or if I'm mistaken.
推荐答案
与您的EDIT相反,将其添加到本地Maven存储库将提供帮助,它可以按以下方式自动执行:
Contrary to your EDIT adding to the local Maven repo will help and it can be automated as follows:
- 请参见 jtahlborn的答案对在单个pom.xml中多个安装:安装文件. (
maven-install-plugin
的当前版本是2.5.2
.我会使用它而不是默认版本.) -
<configuration>
的外观应为:
- See jtahlborn's answer to Multiple install:install-file in a single pom.xml. (The current version of the
maven-install-plugin
is2.5.2
. I'd use that rather than the default.) The
<configuration>
s should look like:
<configuration>
<file>${project.basedir}/path/to/your/libs/lib-X.jar</file>
<repositoryLayout>default</repositoryLayout>
<!-- match the dependency declaration for this artifact -->
<groupId>logan.wlv</groupId>
<artifactId>lib-X</artifactId>
<version>x.y.z</version>
<packaging>jar</packaging>
<!-- -------------------------------------------------- -->
</configuration>
将install-plugin
声明放入构建配置文件,例如lib
.
Put the install-plugin
declaration into a build profile, e.g. lib
.
在每一个新PC上运行一次mvn initialize -P lib
(并在libs
的内容之后更改一次,因此更改了install-plugin
声明),然后再调用首先解决依赖关系的任何阶段,例如compile
.
Run mvn initialize -P lib
once on every new PC (and once after the contents of libs
, and hence the install-plugin
declaration, changed) before invoking any phase that resolves dependencies first, e.g. compile
.
或
-
使用以下方法进一步自动化:
Automate this even further with:
<profile>
<id>lib</id>
<activation>
<file>
<missing>${settings.localRepository}/logan/wlv/lib-X/x.y.z/lib-X-x.y.z.jar</missing>
</file>
</activation>
...
<profile>
这种功能仅在mvn initialize
时即可运行,而无需第一次激活显式配置文件.
Such being able to run just mvn initialize
without the explicit profile activation the very first time.
这篇关于我想使用Maven从我的libs项目文件夹中加载所有JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!