JMU JMU - Department of Computer Science
Help Tools
Lab: Skills - Creating Executable .jar Files in Eclipse


Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.

Getting Ready: Before going any further, you should:

  1. This lab is a simulation of a part of the process that is being used to create a product named Wherez for the (hypothetical) company Nearby. The team is using an incremental process known as Scrum, which divides the work up into sprints.

    If you have not already done so, you must complete the lab on serialization before you can start this lab. If you also completed the lab on GUI modification you can start from there.

  2. Read the course "Help" page on that discusses creating executable/runnable .jar files in Eclipse.
  3. Read the sprintable stories.

1. Creating an Executable .jar File with Defects: This part of the lab will help you understand why the existing implementation is not ready to be deployed.
  1. Without changing the code, create an executable .jar file for Wherez.
  2. Run Wherez (from outside of the IDE) using the executable .jar file. What are the defects?
    The buttons do not have icons. (In fact, because of this problem, the buttons may not exist or be too small to see.)
    Expand
  3. Inspect the code that loads the icons. Where are they loaded from?
    The working directory/folder (since no path is specified). When Eclipse runs an application, it first changes the working directory to the project directory/folder. Since there is where the icons are, the application runs properly from inside of Eclipse.
    Expand
  4. What needs to be done instead?
    We need to load the icons from inside of the .jar file. One way to do this is to use the ClassLoader infrastructure.
    Expand
2. Tasks Required to Satisfy the Acceptance Criteria: The sprintable stories have been decomposed into the following tasks.
  1. Create an icons package inside the src directory/folder.
  2. If necessary, right-click on the folder, pull down to "Build Path", and across to "Include" to ensure that it will be copied to the bin directory when the code is executed. (If "Include" isn't an option then it has already been included.)
  3. Copy the icons into the icons package in the IDE.
  4. Delete the original icons.
  5. Modify the loadImageIcon() method in the WherezWindow class so that it uses the ClassLoader infrastructure.
      private ImageIcon loadImageIcon(String name)
      {
        URL url = this.getClass().getResource("/icons/"+name);
        ImageIcon icon = new ImageIcon(url);
        return icon;
      }
        
    Expand
  6. Run the application from within Eclipse to make sure it still has the icons.
  7. Create an executable .jar file.
  8. Run the executable .jar file to make sure it now has the icons.
  9. Change the icon of the executable .jar file.

Copyright 2021