如何创建我自己的 Java 库(API)? [英] How to create my own java library(API)?

查看:24
本文介绍了如何创建我自己的 Java 库(API)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Java 创建了一个程序并设计了它,以便我希望它们出现在 main 中的方法(getter 方法),我可以在启动包含这些方法的类后轻松调用它们.

I created a program in Java and I designed it so that methods that I want them to appear (getter methods) in the main, I can call them easily after initiate the class that holds these methods.

问题是,我需要让这个应用程序(包含 getter 方法)像一个 API,这样我就可以让我的应用程序让开发人员在需要时使用我的函数(getter 方法),并且他们只需要添加这个文件(我认为完成后的 API 显示为 .jar 文件).

The question is that, I need to make this application (that holds the getter methods) to be like an API so that I can give my application for developers to use my functions (the getter methods) if they need them, and only what they need is to add this file (I think the API after is done shown as .jar file).

如何才能使我的代码可在其他应用程序中重用?我认为它类似于 .dll.

How can I make it so that I can make my code reusable with other application? It's similar to the .dll, I think.

非常感谢;)

推荐答案

创建 JAR.然后包含 JAR.该 JAR 中的任何类都将可用.如果您提供 API,请确保保护您的代码.不要向最终用户公开任何不应使用的方法/属性.

Create a JAR. Then include the JAR. Any classes in that JAR will be available. Just make sure you protect your code if you are giving out an API. Don't expose any methods / properties to the end user that shouldn't be used.

针对您的评论,请确保在打包 JAR 时不包含源代码.只包含类文件.这是你能做的最好的事情.

In response to your comment, make sure you don't include the source when you package the JAR. Only include the class files. That's the best you can really do.

这篇关于如何创建我自己的 Java 库(API)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆