Atpakaļ
1. Preparation of workstation
Tālāk
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 JTM.zip file
  2. Open 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/student/Downloads/JTM.zip
    5. 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:

    cd
    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 eclipse:eclipse
  3. Refresh project explorer in Eclipse

Checkpoints

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 (Hello.java file) with public static void main(String[] args) method in it.
    1. In the Project Explorer view, select package: main.java.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 code into main method, which prints "Hello world!" into system console, for example:

    System.out.println("Hello world!");
  5. 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/Aaaa/
    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

Optional

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/JTM.zip,
  4. Finish.
    Then you can import project as it was described earlier.

Atpakaļ
1. Preparation of workstation
Tālāk
2.1 Git version control
Tagi:
Izveidojis Valdis Vītoliņš 2017-01-03 10:07
Pēdējais mainījis Valdis Vītoliņš 2019-01-28 20:58
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License