简体   繁体   English

使用Jar文件创建Java库或类或包

[英]Creating a Java Library or class or package with Jar files

I have about 100 jar files and I think I want to make a library with them. 我大约有100个jar文件,我想与他们建立一个图书馆。 What is the best way to do this? 做这个的最好方式是什么? How does importing work with this. 导入如何与此一起工作。 Do I still have to ask for each class or do I just refer to the new library? 我还是要问每堂课还是只是参考新图书馆?

More detail 更多详情

I have the GeoTools9.4 package (in a zip). 我有GeoTools9.4包(以zip格式)。 It has about 100 jar files. 它有大约100个jar文件。 When I import these into my project in eclipse, it takes each jar file and stuffs it in and clutters up my structure. 当我将它们导入eclipse中的项目时,它将获取每个jar文件并将其填充进去,并使我的结构混乱。 So I think I want a library (or a package or a class) I am not sure what the terminology is here. 所以我想我想要一个库(或一个包或一个类),我不确定这里的术语是什么。

More detail on how to call the classes in the new library. 有关如何在新库中调用类的更多详细信息。 Right now here is how I call the classes 现在这是我如何称呼课程

import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;

If I put all of these jar files in a library can I replace the above lines with a new import like 如果我将所有这些jar文件都放在一个库中,可以将上面的行替换为新的导入,例如

import org.geotools.local

or do I not need to change the way they are called? 还是不需要更改它们的调用方式?

I propose you to use a Maven for this stuff. 我建议您使用Maven进行此操作。

Maven is a greay build tool, that could take care of problems, like adding dependency jars to a project. Maven是一个灰色的构建工具,可以解决问题,例如向项目添加依赖项jar。 Also, GeoTools support Maven and have a nice manual for it ( http://docs.geotools.org/latest/userguide/tutorial/quickstart/maven.html ) 此外,GeoTools支持Maven并为其提供了不错的手册( http://docs.geotools.org/latest/userguide/tutorial/quickstart/maven.html

About last question - when you'll add this libraries, full name of these classes will be the same, so you must import and use them as you import them right now. 关于最后一个问题-添加这些库时,这些类的全名将相同,因此您必须在导入它们的同时导入和使用它们。

This is not usually refered to as "calling" the classes, but rather importing the classes meaning that they become available to the class that uses them. 通常不将其称为“调用”类,而是导入类意味着它们可用于使用它们的类。

No matter how you have those classes (in many jars or a single jar) you still need to have the import statements in the beggining of the class file for the source to be compiled 无论您如何拥有这些类(在多个jar或单个jar中),您仍需要在类文件的开头中包含import语句,以便编译源

I am not sure how Eclipse "clutters up" your structure. 我不确定Eclipse如何“弄乱”您的结构。 You can place all the jars in a single folder eg lib and then import them into your eclipse project from that folder. 您可以将所有jar放在单个文件夹(例如lib ,然后将其从该文件夹导入到eclipse项目中。 If you mean that the jars show up in the left pane then there are filters that can hide them. 如果您的意思是这些罐子显示在左窗格中,则可以使用过滤器将其隐藏。 In Eclipse there is the concept of a Working set where you can select what it would be visible and what not. 在Eclipse中,有一个工作集的概念,您可以在其中选择可见的内容和不可见的内容。

I hope it helps 希望对您有所帮助

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

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