简体   繁体   中英

Adding External jar copy to Project

I created a project but I am using an external library for it. enter link description here

I added the library to my Beans as follows:

  1. Right click on folder "Libraries"
  2. Add Library
  3. Create...
  4. Gave it a name "gson 2.7"
  5. Picked the class, source and javadoc files.

I went on and continued programming and then I added my code to Github. Then when I cloned it my Library was missing.

How can I fix this ? How can I make it dynamic so I dont have to worry about this anymore. In other words I need to add the library to my code and not just the reference.

Thanks a lot for the help

只需将您的库的副本上传到github。

I have not used netbeans, but from what I understand it adds the jar somewhere outside of your project directory, and it simply adds the location of the jar to your classpath. When you upload and then clone the project from github, the jars are not uploaded/cloned, and the project structure metadata for your project is also lost from netbeans.

My suggestion is to learn and start using a build tool like maven. It takes up the responsibility of adding your dependency libraries everytime, given that you have an internet connection. It also adds the libs to the target directory of your project folder, so you probably will need the internet connection only once. The libs will be uploaded and cloned back from the github repo everytime.

IDEs like eclipse have inbuilt support for maven, so you don't even have to worry about executing the mvn commands. Here's a tutorial that will get you intrigued - with the IDE that you prefer.

https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html

Thanks a lot for all the replies and comments.

Technically there are two approaches to my problem. For this articular example I chose to copy the external jar files to my project.

1. Copy jar files to your project.

  • Go to project properties
  • Under Libraries folder make sure to set up a libraries folder by following the steps.
  • Add Library at the bottom ( you can create or import; since I already had gson in Netbeans I just imported it.)
  • Press ok to confirm and you are done!

2. Use Maven

  • Go to plugings and make sure you have all Maven plugins installed, if not do so.
  • Create an new project and choose maven/java application
  • Follow the prompts
  • At this point you can start coding (in my case I just imported my class files from the other project)
  • Right click in "Dependencies folder and then "Add Dependency"
  • Under query type the repository you are looking for; in my case "com.google.code.gson : gson : 2.7"
  • Click add and you are done!

Thanks a lot to everyone for the help :)

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