简体   繁体   中英

Adding libraries to NetBeans project without Maven

I have a project in NetBeans and a jar library that I want to add to it. 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?

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. I'm using 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. 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

group-id: the group that the file should be registered under eg → com.google.code

artifact-id: the artifact name for the file eg → kaptcha

version: the version of the file eg → 2.3

packaging: the packaging of the file eg → jar

As alternative you can directly add your jar as dependency too your maven project. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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