简体   繁体   English

将外部jar副本添加到Project

[英]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: 我将库添加到我的Beans中,如下所示:

  1. Right click on folder "Libraries" 右键单击文件夹“Libraries”
  2. Add Library 添加库
  3. Create... 创造...
  4. Gave it a name "gson 2.7" 给它起个名字“gson 2.7”
  5. Picked the class, source and javadoc files. 挑选了类,源和javadoc文件。

I went on and continued programming and then I added my code to Github. 我继续编程然后将代码添加到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. 我没有使用netbeans,但据我所知,它在项目目录之外的某处添加了jar,它只是将jar的位置添加到类路径中。 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. 当您从github上传然后克隆项目时,不会上传/克隆jar,并且您的项目的项目结构元数据也会从netbeans中丢失。

My suggestion is to learn and start using a build tool like maven. 我的建议是学习并开始使用像maven这样的构建工具。 It takes up the responsibility of adding your dependency libraries everytime, given that you have an internet connection. 由于您具有Internet连接,因此每次都需要添加依赖库。 It also adds the libs to the target directory of your project folder, so you probably will need the internet connection only once. 它还将lib添加到项目文件夹的目标目录中,因此您可能只需要一次Internet连接。 The libs will be uploaded and cloned back from the github repo everytime. 每次都会从github repo上传和克隆lib。

IDEs like eclipse have inbuilt support for maven, so you don't even have to worry about executing the mvn commands. 像eclipse这样的IDE内置了对maven的支持,所以你甚至不必担心执行mvn命令。 Here's a tutorial that will get you intrigued - with the IDE that you prefer. 这是一个让您感兴趣的教程 - 使用您喜欢的IDE。

https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html 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. 对于这个关节示例,我选择将外部jar文件复制到我的项目中。

1. Copy jar files to your project. 1.将jar文件复制到项目中。

  • 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.) 在底部添加库(您可以创建或导入;因为我已经在Netbeans中使用了gson,我刚刚导入它。)
  • Press ok to confirm and you are done! 按确定确认即可完成!

2. Use Maven 2.使用Maven

  • Go to plugings and make sure you have all Maven plugins installed, if not do so. 转到插件并确保安装了所有Maven插件,如果不这样做的话。
  • Create an new project and choose maven/java application 创建一个新项目并选择maven / java应用程序
  • 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" 右键单击“Dependencies文件夹然后”添加依赖项“
  • Under query type the repository you are looking for; 在查询下键入您要查找的存储库; in my case "com.google.code.gson : gson : 2.7" 在我的情况下“com.google.code.gson:gson:2.7”
  • Click add and you are done! 点击添加即可完成!

Thanks a lot to everyone for the help :) 非常感谢大家的帮助:)

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

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