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

查看:109
本文介绍了如何创建自己的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天全站免登陆