Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

android - How do I make a Java library with Eclipse?

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?

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?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Option 1: Just use the source

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

Properties > Java Build Path > Tab: Source > Add Folder...

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

Option 2: Create and add the library to the Build-Path

Adding an existing Jar (your own library):

If it is in the workspace:

Properties > Java Build Path > Tab: Libraries > Add JARs...

If it is somewhere on the drive:

Properties > Java Build Path > Tab: Libraries > Add External JARs...

Exporting a source folder as a library:

Context Menu of Source Folder > Export > Jar File

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...