简体   繁体   English

在没有 Maven 的情况下将库添加到 NetBeans 项目

[英]Adding libraries to NetBeans project without Maven

I have a project in NetBeans and a jar library that I want to add to it.我在 NetBeans 中有一个项目和一个 jar 库,我想将其添加到其中。 But I don't know exactly how.但我不知道具体怎么做。 I know that in Eclipse this can be done by creating a lib folder in the project and putting the jars into it, but is this gonna work in NetBeans?我知道在 Eclipse 中,这可以通过在项目中创建一个 lib 文件夹并将 jars 放入其中来完成,但这在 NetBeans 中会起作用吗?

I tried to do it this way and run the project, but the exception it throws makes me think that the library isn't found by the program.我尝试这样做并运行该项目,但它抛出的异常让我认为该程序未找到该库。 I haven't found the library in the Maven repository, so I want to add it directly.我在Maven仓库里没有找到这个库,所以想直接添加。 I'm using NetBeans 12.0.我正在使用 NetBeans 12.0.

You may add you local library to your.netbeans project, but this would be overwritten as this project is managed by maven. The better choice is to add your jar file to your local.m2 storage.您可以将您的本地库添加到您的 .netbeans 项目,但是这将被覆盖,因为该项目由 maven 管理。更好的选择是将您的 jar 文件添加到您的 local.m2 存储。 You may your library by the command:您可以通过以下命令访问您的图书馆:

mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<packaging> \
-DgeneratePom=true

path-to-file: the path to the file to load eg → c:\kaptcha-2.3.jar path-to-file:要加载的文件的路径 eg → c:\kaptcha-2.3.jar

group-id: the group that the file should be registered under eg → com.google.code group-id:该文件应注册的组,例如 → com.google.code

artifact-id: the artifact name for the file eg → kaptcha artifact-id:文件的工件名称,例如 → kaptcha

version: the version of the file eg → 2.3版本:文件的版本,例如 → 2.3

packaging: the packaging of the file eg → jar packaging: 文件的包装 eg → jar

As alternative you can directly add your jar as dependency too your maven project.作为替代方案,您可以直接将 jar 添加为 maven 项目的依赖项。 You should use:你应该使用:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM