1. Preparation of workstation
2.1 Git version control

2. exercise: Preparation of Java development project

Review Introduction to Java


Review notes about practical exercise


Practical tasks

Import project

  1. Download file
  2. Open Eclipse:
    1. In start menu select start menu Start — Programming — Eclipse
    2. select menu: File— Import...
    3. General— Existing projects into workspace, Next
    4. Check Select archive file 
    5. Select downloaded file e.g. /home/student/Downloads/
    6. Finish

Rename project

  1. Generate your own unique project name with following command:

    head -c 32 /dev/urandom|sha256sum|xxd -r -p|base64|cut -b -4|tr "+/=" "abc"
  2. Right click on JTM and select Refactor—Rename
  3. Rename project in form: Aaaa (where Aaaa is actual output from previously entered command)
  4. Open your project folder e.g. /home/student/workspace/Aaaa.
  5. Open file pom.xml and change line <artifactId>JTM</artifactId> to: <artifactId>Aaaa</artifactId>
Generated code e.g. Aaaa will be used as unique identifier for your project and knowledge checks!

Rebuild project

  1. Open terminal and create M2_REPO variable for Eclipse:

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

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


help Check that project name in Eclipse is e.g. Aaaa
help Check that your project is located in folder e.g. /student/workspace/Aaaa/
help Check that file /home/student/workspace/Aaaa/.project has line: <name>Aaaa</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 ( file) with public static void main(String[] args) method in it.
    1. In the Project Explorer view, select package:
    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 code into main method, which prints "Hello world!" into system console, for example:

    System.out.println("Hello world!");
  5. Run as JUnit test to test proper implementation of this class.
    1. Right click on
    2. Select Run As — JUnit Test
    3. Check that JUnit view shows green status bar
    4. To to doube-check system configuration, run also 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/Aaaa/
    java -version
    javac -cp target/classes -d target/classes src/main/java/jtm/activity02/
    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


Review topic: Extra 14: Java building tools

Export project:

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

1. Preparation of workstation
2.1 Git version control
Created by Valdis Vītoliņš on 2017-01-03 10:07
Last modified by Valdis Vītoliņš on 2019-08-05 23:55
Xwiki Powered
Creative Commons Attribution 3.0 Unported License