Question: How do you maintain one authoritative version of code (especially for a utility function) across
many projects?
Answer: Create a library.
Once a file is packaged (with an appropriate version number and usage documentation) the binary can be
distributed and imported into Projects without needing to manage a lot of source files.
(This also allows multiple helper files to be bundled together and YES, Unit Tests!)
Create a new project with only the source object(s) which constitute a logical library (should be small)
Right click on the ProjectName -> Export (Java -> JAR file)
Eclipse GUI handles all of the Manifest file and sealing the Jar options
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
To add a library to a project which requires that functionality...
Option 1: Right click on the Project -> Build Path -> Add External Archives -> browse to the .jar file
(Referenced Libraries will update with the Library.jar name and the full path in gray)
This option centralizes a library that's used by multiple projects.
Option 2: copy and paste the library.jar into workplace/projectname/lib
directory and then browse in the Package Explorer -> Refresh on the lib directory
You'll see the file, right click on it and choose to Add it to the Build Path.
(Referenced Libraries will update with the Library.jar name and the "lib" folder will too)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Now all methods that are in the library (depending on whether they're Public, Protected, but not Private)
are accessible to the new Project
TODO: JavaDoc for a Library