如何使用Eclipse创建Java库? [英] How do I make a Java library with Eclipse?

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

问题描述

我一般来说对Java和Android编程还是比较陌生,但是我想创建一个小的Java库,以便在普通(非Android)Java应用程序和Android应用程序之间共享一些代码;所以我的问题是用Eclipse创建普通Java库的最佳方法是什么?

I'm fairly new to Java and Android programming in general but I would like to create a small Java library for sharing some code between an ordinary (non-Android) Java application and an Android application; so my question is what is the best way of creating an ordinary Java library with Eclipse?

我在任何地方都找不到从Eclipse创建新Java库项目的选项;这是否意味着我必须使用普通的Java应用程序作为起点?因为这也将用于普通的Java应用程序,所以我不能使用Android库.

I didn't find anywhere the option for creating a new Java library project from Eclipse; does this mean that I must use an ordinary Java application as my starting point? As this will be used for an ordinary Java application as well, I cannot use an Android library.

此外,我必须设置哪些选项?

Also, what would be the options that I must set up?

最后,由于该库将与应用程序项目位于同一工作区中,如果我可以建立到该库项目的直接链接,创建JAR文件是否仍然是强制性的?

Finally, as this library will be in the same workspace as the application projects, is it still mandatory to create a JAR file if I can establish a direct link to the library project?

推荐答案

如果使用相同的工作空间,则不得创建任何库.

You must not create any library, if you use the same workspace.

选项1:仅使用源代码

在具有依赖项的项目属性中,您可以添加另一个源文件夹:

In the properties of the project which has the dependencies you can add another source-folder:

属性> Java构建路径>标签:源>添加文件夹...

在项目"选项卡中,您也可以将整个项目添加"到另一个项目.有很多方法可以实现您的目标.

In the Project Tab you can "add" the whole project to the other project, too. There are many ways to achieve your goal.

选项2:创建库并将其添加到构建路径

添加现有的Jar(您自己的库):

Adding an existing Jar (your own library):

如果它在工作空间中:

属性> Java构建路径>标签:库>添加JAR ...

如果它在驱动器上某处:

If it is somewhere on the drive:

属性> Java构建路径>标签:库>添加外部JAR ...

将源文件夹导出为库:

源文件夹>导出> Jar文件的上下文菜单

有两种类型:可执行的Jar和普通"的Jar.您不需要可执行的Jar.

There are two types: Executable Jars and "normal" Jars. You don't need an executable Jar.

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

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