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.

2. Preparation of Java project

Review Introduction to Java

Practical exercise

Practical tasks

Import project

  1. Open Eclipse IDE:
    1. open IDEs/eclipse folder in file manager,
    2. double click on eclipse file and select Execute.
  2. Download JTM.zip file
  3. Extract JTM.zip archive in the project folder of your IDE, e.g. in workspace folder
  4. Import Java project in Eclipse:
    1. select menu: File— Import...
    2. select Maven— Existing Maven Projects and press Next
    3. Check Select root directory and choose your workspace folder and open it
    4. Select extracted project from archive /JTM/pom.xml...
    5. Finish

Rename project

  1. Get unique identifier for your project from your teacher (e.g. uXX)
  2. Right click on JTM and select Refactor—Rename
  3. Rename project in form: uXX (where uXX is actual output from previously entered command)
  4. Open your project folder e.g. /home/student/workspace/uXX.
  5. Open file pom.xml and change line <artifactId>JTM</artifactId> to: <artifactId>uXX</artifactId>

Above and below replace uXX with your actual code, e.g. uXX.
Given code e.g. uXX will be used as unique identifier for your project and knowledge checks!

Rebuild project

  1. Go to your project and regenerate project meta-info for Eclipse, e.g.:

    cd ~/workspace/uXX
    mvn clean compile eclipse:clean eclipse:eclipse
  2. Refresh project explorer in Eclipse: select project in Package Explorer and press F5.


help Check that project name in Eclipse is e.g. uXX
help Check that your project is located in folder e.g. /student/workspace/uXX/
help Check that file /home/student/workspace/uXX/.project has line: <name>uXX</name>
help Select Window — Preferences, search for Java — Build Path — Class Variables and check M2_REPO has value /home/student/.m2/repository. If this variable doesn't exist, press New..., enter necessary name and value, press OK and agree to recompile entire project.

Implement TODO

  1. Select menu Window — Open Perspective — Java
  2. Right click on Resource button and select Close
  3. Use code generation to create class Hello (Hello.java file) with public static void main(String[] args) method in it.
    1. In the Project Explorer view, select package: jtm.activity02
    2. Right click on the package and select: New — Class
    3. For field Name enter: Hello
    4. In group Which method stubs would you like to create? select public static void main(String[] args)
    5. Press Finish
  4. Add following code into main method, to print hello message in different languages:

    System.out.println("Hello! Sveicināti! 你好!");

    If you can't properly save non-Latin characters as literal value of printed message, check your project settings:

    1. Right click on project root entry (e.g. uXX) in Package explorer:
    2. Select Resource menu and check that Text file encoding is UTF-8 either as inherited setting from container,
      or set explicitly.
  1. Run HelloTest1.java as JUnit test to test proper implementation of this class.
    1. Right click on HelloTest1.java
    2. Select Run As — JUnit Test
    3. Check that JUnit view shows green status bar
    4. To to doube-check system configuration, run also ConfigurationTest1.java Junit in jtm.activity01 package.
  2. If necessary, change waitRatio = 1f value in jtm.testssuite.AllTests class to bigger value to allow tests to run longer

Learn to compile and execute classes

In Eclipse

  1. Select class and activate menu Run — Run as... — Java application

In command line

  1. Open terminal and enter commands:

    cd ~/workspace/uXX/
    java -version
    javac -cp target/classes -d target/classes src/main/java/jtm/activity02/Hello.java
    java -cp target/classes jtm.activity02.Hello

Run Unit test

  1. Select menu Run— Run as— Java Application
  2. Select menu Run— Run as— JUnit Test
  3. Check that unit test passes

Where Eclipse settings are stored

  • .project .classpath files of the project
  • .settings folder of the project
  • .metadata folder of the workspace
  • .eclipse folder of the Eclipse

Where IntelliJ IDEA settings are stored

  • name.iml file and .idea folder of the project
  • .config/JetBrains/Idea.... folder of the IDEA

Optional tasks

Create desktop entry for Eclipse

  1. Right click on desktop
  2. Select Create launcher...
  3. Enter:
    1. name: Eclispse,
    2. Command: /home/student/IDEs/eclipse/eclipse
    3. If you like select Icon: /home/student/IDEs/eclipse/icon.xpm
  4. Save desktop entry

Review topic: Extra 16: Java building tools

Export project:

  1. Select project package explorer view
  2. select File — Export... — General — Archive File,
  3. to archive file: /home/student/uXX.zip,
  4. Finish.
    Then you can import project as it was described earlier.


Created by Valdis Vītoliņš on 2017-01-03 08:07
Last modified by Valdis Vītoliņš on 2021-08-09 12:38
Xwiki Powered
Creative Commons Attribution 3.0 Unported License