CODEBLACK
CODEBLACK

Reputation: 1249

Eclipse JAR export settings for external JAR file creation(for import into another project)

I have a project where I want to add an external JAR file. The desired external JAR file has a nifty Github page with source, but no pre-compiled JAR file.

These are the steps I've completed so far:

1. I have downloaded the source in a zip. (its Twinkle from SwingFx.ch in case you're interested)
2. I have extracted the zip file to my workspace.
3. I have created a new project with the same name as the extracted folder from the zip file. (project loads the source successfully)
4. I select the export option from the File menu and selected the 'JAR file' option and clicked next.

Note: I had to add an external library to the above Twinkle project for it to build successfully (in case that makes a difference to the settings).

On the JAR File Specification page there are multiple check-box options available(see below):

Export generated class file and resources
Export all output folder for checked projects
Export Java source files and resources
Export refactorings for checked projects
Compress the contents of the JAR file
Add directory entries

I am not sure which are supposed to be selected and if it makes a difference in the behaviour of the project I will add the (soon-to-be) exported JAR file to. I tested it by exporting with the default settings. This worked ok.. However, I now do not know if I should have chosen different settings in case of any reasons I am not aware of. I am not sure if there are specific settings I should choose when I intend for the JAR file to, specifically, be added as an external JAR file to another project.

Please enlighten me!

Upvotes: 3

Views: 1618

Answers (1)

jlr
jlr

Reputation: 1530

This is a traditional Java library that uses Maven. It should be fairly easy to build using Maven, which should be better and quicker to build this, if you already have Maven and git installed.

Let's consider that you did not download the source file as a zip, but take the github approach, where you'd use git to download the source code.

  1. If you don't have git, download its latest version and install it.
  2. If you don't have Maven, download its latest version and install it.
  3. Once Maven and git are installed, make sure the Maven and git binaries are configured in your environment PATH variable. If not set, you would, on the Windows platform and for Maven binaries, set it this way (using the default installation path):

    set PATH=%PATH%;C:\Program Files (x86)\Apache\maven-3.1.1\bin

  4. Create and change directory in a work directory of your choice, that we'll refer to %work_directory% from now on.

  5. Run the following:
cd %work_directory% 
git clone https://github.com/spreiter301/Core.git
git clone https://github.com/spreiter301/Twinkle.git
cd Core
mvn clean install
cd ../Twinkle
mvn package

6. Retrieve the twinkle-1.0.0.jar file in the newly created '%work_directory%/Twinkle/target' folder.

In this case, it was necessary to retrieve the Core library because it is a dependency of the Twinkle project. Normally, this is not necessary because dependencies are automatically retrieved from a maven repository. But in that case, that dependency is not available on any Maven repository. Hence we manually retrieved the dependency from github, compiled it and installed it in your local cached repository. Then we could package the Twinkle project into the JAR file.

This should do it. If you want a 5 minutes tutorial on Maven, there is a tutorial for this here. I highly recommend it, you will encounter this often in the Java world. Maven is the standard build tool for Java, just like 'make' is for C, 'rake' for Ruby, 'sbt' for Scala, etc..! Good luck with the rest.

Upvotes: 2

Related Questions