java读取libs下文件,我想使用Maven从我的libs项目文件夹中加载所有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.

My issue is how to specify to Maven to include those JARs during packaging, building etc.?

New to Maven, sorry if it is a stupid question.

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.

解决方案

Contrary to your EDIT adding to the local Maven repo will help and it can be automated as follows:

See jtahlborn's answer to Multiple install:install-file in a single pom.xml. (The current version of the maven-install-plugin is 2.5.2. I'd use that rather than the default.)

The s should look like:

${project.basedir}/path/to/your/libs/lib-X.jar

default

logan.wlv

lib-X

x.y.z

jar

Put the install-plugin declaration into a build profile, e.g. lib.

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.

or

Automate this even further with:

lib

${settings.localRepository}/logan/wlv/lib-X/x.y.z/lib-X-x.y.z.jar

...

Such being able to run just mvn initialize without the explicit profile activation the very first time.

安卓项目的`libs`目录通常存放的是第三方的JAR包或.aar文件,如果要在Maven项目作为依赖管理,你需要将这些库转换为Maven兼容的格式。以下是步骤: 1. **将JAR转换为Maven依赖**: 如果是普通的JAR包(`.jar`),你需要创建一个新的`pom.xml`文件,将这个JAR添加到项目的`dependencies`部分。例如: ```xml <dependency> <groupId>com.example</groupId> <artifactId>your-jar-name</artifactId> <version>1.0.0</version> <type>jar</type> <scope>system</scope> <systemPath>${project.basedir}/libs/your-jar-file.jar</systemPath> </dependency> ``` 2. **将.AAR转换为Maven依赖 (适用于Android Library)**: 对于Android AAR (Archives),可以考虑将其发布到Maven仓库,或者直接在Maven pom.xml添加本地路径,但这种方式不推荐长期使用,因为它不便于版本管理和团队协作。AAR可以直接在Android项目通过Gradle依赖管理。 3. **构建Maven Repository**: 如果你长期维护这个依赖,最好将JAR/AAR打包并发布到Maven央仓库(如Jcenter、Maven Central等)或私有仓库,这样其他开发者就可以像引用任何其他Maven依赖一样引用它。 4. **Gradle配置**: 如果你是用Gradle构建项目,可以在`build.gradle`文件使用`implementation`或`api`关键字来声明依赖,对于本地库可以用`fileTree`或`aar`插件。 注意,将本地库依赖Maven项目并不是最佳实践,因为这会增加项目的复杂性和维护困难。理情况下,还是建议将库发布到公开的Maven仓库以便团队共享。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值