If it is not explicitly told in following recipe, setting up services are described for Ubuntu 20.04 server, but applications are described for Xubuntu 20.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

19. Java graphical application

  1. Review the presentation Java Graphical Frameworks

    Tasks

    1. Install the Eclipse WindowBuilder plugin.
    2. Explore the jtm.activity19 package
    3. Implement the ColorSlider class so that the color sliders change the background color of the test area

    Export the application to an executable *.jar file

    1. Export the ColorSlider class as an executable jar file. In Eclipse, do the following:
      1. Right-click the ColoSlider.java file in the Package Explorer and select Export...
      2. Select Java — Runnable JAR file and click Next,
      3. In the Launch configuration section, select ColorSlider - Aaaaaa (where Aaaaaa is your project),
      4. In the Export destination section, enter Aaaaaa/src/main/java/jtm/activity19/color-slider.jar (where Aaaaaa is your project).
      5. Under Library handling, select Package required libraries into generated JAR
      6. Click Finish,
      7. If errors/warnings are reported, click OK (you can ignore the warnings, but the errors must be fixed).
    2. Open a terminal and test the jar file from the command line:

      cd ~/Aaaaaa/src/main/java/jtm/activity19/
      java -jar color-slider.jar
    3. Test the ColorSliderTestSuite test suite tests to pass.

    Minimize the jar file

    If this is done as a simple export in Eclipse, the jar file contains all the libraries listed as project dependencies that are not required only for the Swing application. You can make the *.jar file much smaller by including only the required libraries.

    1. Install the ant build tool:

      sudo apt install ant
    2. In the Package Explorer, right-click on the ColoSlider.java file and select Export...
    3. Select Java — Runnable JAR file and click Next,
      1. In the Export destination section, enter Aaaaaa/src/main/java/jtm/activity19/color-slider.jar (where Aaaaaa is your project).
      2. In the Library handling section, select Package required libraries into generated JAR
      3. Check Save as ANT script and set its location (e.g. export.xml in your project) and finish exporting.
    4. Open the export.xml file and delete all entries similar to zipfileset dir="... except:

      <zipfileset dir="/home/student/.m2/repository/com/miglayout/miglayout/3.5.5" includes="miglayout-3.5.5.jar"/>

      Do not delete the <fileset dir="${dir.buildfile}/target/classes"/> line, which can easily be lost among the zipfileset dir="..." lines!

    5. Right-click export.xml and select Run as — Ant build.
    6. Verify that color-slider.jar is now a few hundred kilobytes in size.

    You can use the ColorSliderTest.java class design as a template for a GUI test for your team's work for the project.

    Additional information


  

Created by Valdis Vītoliņš on 2025-01-28 17:49
Last modified by Valdis Vītoliņš on 2025-01-28 17:50
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License