简体   繁体   English

如何使用Java库?

[英]How do I make use of java library?

My project is to develop a network analysis tool and I decided to use JUNG library. 我的项目是开发网络分析工具,因此我决定使用JUNG库。 but I don't know how to get started and make use of it?I'm using eclipse IDE so how can I intergrate it in eclipse? 但是我不知道如何开始使用它?我正在使用eclipse IDE,如何在eclipse中集成它? thanks. 谢谢。

To integrate an external library in Eclipse, simply go to your package explorer side view, right click on your project or on some file within your project, and go to properties. 要在Eclipse中集成外部库,只需转到包资源管理器侧视图,右键单击您的项目或项目中的某些文件,然后转到属性。 In the Java Build Path section, go to the libraries tab and add your library there. 在“ Java构建路径”部分中,转到“库”选项卡,然后在其中添加您的库。 That should make it show up in your build path so that it will compile with your project. 那应该使它显示在您的构建路径中,以便它可以与您的项目一起编译。

I should mention that if it's just an external jar, simply click Add External JARs instead of Add Library. 我应该提到,如果只是外部jar,只需单击“添加外部JAR”而不是“添加库”。

Drag the jar files into Eclipse and drop them on your project (I believe you have only one). 将jar文件拖放到Eclipse中,然后将其放在您的项目中(我相信您只有一个)。 Right click on the jar file, and choose "Add to Build Path". 右键单击jar文件,然后选择“添加到构建路径”。 It should then be immediately accessible. 然后应该立即可以访问它。

And just in case your working on a eclipse plugin or even an eclipse-rcp application, you should create a new plugin project that just contains this library. 并且以防万一您使用eclipse插件甚至eclipse-rcp应用程序,您应该创建一个仅包含此库的新插件项目。 It's very simple: just open the wizard to create a new project: File > New > Project... > Plug-in Development > Plug-in from existing JAR archive 非常简单:只需打开向导即可创建一个新项目:“ 文件”>“新建”>“项目...”>“插件开发”>现有JAR存档中的插件

In any other case: create either a copy of the library directly in your project (I suggest: lib/jung.jar) and add that library to your buildpath (right-click on library) or create a User Library with the jar(s) and add that user library to the projects buildpath. 在任何其他情况下:直接在您的项目中创建该库的副本(我建议:lib / jung.jar),然后将该库添加到您的构建路径中(右键单击库),或者使用jar创建用户库),然后将该用户库添加到项目的buildpath中。

Advantage of user libraries: reusable in the same workspace & projects are loosely coupled to the dependencies (you can update a library without changing the project). 用户库的优势:在同一工作空间中可重用,并且项目与依赖关系松散耦合(您可以在不更改项目的情况下更新库)。 Disadvantage: user libraries are defined in the workspace, so when you import the project to a different workspace, you'll break your dependencies. 缺点:用户库是在工作空间中定义的,因此,当您将项目导入到其他工作空间时,将会破坏依赖关系。

A compromise might be to create one project that only contains libraries and add that project to he build paths. 一种折衷办法是创建一个仅包含库的项目,然后将该项目添加到构建路径中。 It's loose coupling like user libraries but you can export and import that project to to/from other workspaces. 它是类似于用户库的松散耦合,但是您可以将该项目导出到其他工作空间或从其他工作空间导入。

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

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