How do I make a Java library with Eclipse?

后端 未结 2 1771
挽巷
挽巷 2020-12-08 19:09

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 appli

相关标签:
2条回答
  • 2020-12-08 19:43

    A Java library is basically a set of JAR files. So what you can do is generate a JAR based on your source code and add it as a external JAR to the Java build path of your Android and non-Android projects.

    0 讨论(0)
  • 2020-12-08 19:49

    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.

    0 讨论(0)
提交回复
热议问题