If it is not explicitly told in following recipe, setting up services are described for Ubuntu 16.04 server, but applications are described for Ubuntu 16.04 and/or Lubuntu 16.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. Download JTM.zip file
  2. Open Eclipse IDE:
    1. open IDEs/eclipse folder in file manager,
    2. double click on eclipse file and select Execute;
  3. Import Java project in Eclipse:
    1. select menu: File— Import...
    2. General— Existing projects into workspace, Next
    3. Check Select archive file
    4. Select downloaded file e.g. /home/uXX/Downloads/JTM.zip
    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/uXX/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. If necessary (for recent Eclipse versions it is not necessary), open terminal and create M2_REPO variable for Eclipse:

    mvn -Declipse.workspace=/home/uXX/workspace/ eclipse:configure-workspace
  2. Go to your project and enerate project meta-info for Eclipse, e.g.:

    cd ~/workspace/uXX
    mvn clean compile eclipse:clean eclipse:eclipse
  3. Refresh project explorer in Eclipse


help Check that project name in Eclipse is e.g. uXX
help Check that your project is located in folder e.g. /uXX/workspace/uXX/
help Check that file /home/uXX/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/uXX/.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.

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/uXX/IDEs/eclipse/eclipse
    3. If you like select Icon: /home/uXX/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/uXX/uXX.zip,
  4. Finish.
    Then you can import project as it was described earlier.


Created by Valdis Vītoliņš on 2020-05-28 10:26
Last modified by Valdis Vītoliņš on 2021-05-24 17:24
Xwiki Powered
Creative Commons Attribution 3.0 Unported License