如何开发自己的 Java 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6496597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:06:34  来源:igfitidea点击:

How can I develop my own Java Library?

java

提问by bremmS

Are there any good tutorials / starting points you can suggest for me to develop my own Java libraries?

是否有任何好的教程/起点可以建议我开发自己的 Java 库?

(I'm thinking about developing a small graphics library at the moment.)

(我目前正在考虑开发一个小型图形库。)

回答by aioobe

How can I develop my own Java Library?

如何开发自己的 Java 库?

As you probably know a Java library is usually simply a jar-file containing some utility classes, aimed to solve problems at a higher level of abstraction than what the classes in the Java Platform API does. So, technically speaking you simply write the classes you would find useful to have in your library, compile them, jar them up and write some good documentation.

您可能知道,Java 库通常只是一个包含一些实用程序类的 jar 文件,旨在解决比 Java 平台 API 中的类所做的抽象级别更高的问题。因此,从技术上讲,您只需编写您认为在库中有用的类,编译它们,将它们打包并编写一些好的文档。

Are there any good tutorials / starting points you can suggest for me to develop my own Java libraries?

是否有任何好的教程/起点可以建议我开发自己的 Java 库?

Writing usefullibraries is a tricky business though. Rather than thinking in terms of what would be a nice design internally, you should think about what would be a nice design for the client to use.

不过,编写有用的库是一项棘手的工作。与其在内部考虑什么是好的设计,您应该考虑什么是供客户使用的好的设计。

I suggest you google for java api design. Here are a few useful hits:

我建议你谷歌java api design。以下是一些有用的点击:

回答by Jesper

This is a very general question. What exactly do you want to know? Developing a library is not much different from developing any other application.

这是一个非常笼统的问题。你究竟想知道什么?开发库与开发任何其他应用程序没有太大区别。

Libraries are normally packaged in JAR files. You package class files into a JAR file using the jartool (if you use an IDE, it might have a way to do this from the IDE).

库通常打包在 JAR 文件中。您可以使用该jar工具将类文件打包为 JAR 文件(如果您使用 IDE,它可能有办法从 IDE 执行此操作)。

See Oracle's very good Java Tutorialsto learn about many different Java programming topics. Java already has a comprehensive graphics API, which you can learn more about in the 2D Graphicstutorial.

请参阅 Oracle 非常好的Java 教程以了解许多不同的 Java 编程主题。Java 已经有一个全面的图形 API,您可以在2D 图形教程中了解更多信息。

回答by Chris

There is a good guide hereon how to create your own API.

有一个很好的指导这里了解如何创建自己的API。

The hardest part of any API design is designing for as many use-cases as possible and to provide interfaces so that users of the library can override standard implementations (where applicable).

任何 API 设计中最困难的部分是设计尽可能多的用例并提供接口,以便库的用户可以覆盖标准实现(如果适用)。