COMP220/285 Lab sessions 1-3

Similar documents
Software Development. COMP220/COMP285 Seb Coope Ant: Structured Build

Getting Started with Eclipse/Java

S A M P L E C H A P T E R

Ant. Originally ANT = Another Neat Tool. Created by James Duncan Davidson Now an Apache open-source project

1. The Apache Derby database

Setting up your Computer

1. The Apache Derby database

1. Go to the URL Click on JDK download option

COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE. Instructor: Prasun Dewan (FB 150,

Using Karel with Eclipse

Laboratory 1: Eclipse and Karel the Robot

Packaging Your Program into a Distributable JAR File

ASSIGNMENT 5 Objects, Files, and a Music Player

Programming Principles 1 (CSC131) & 2 (CSC132) Software usage guide

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Purpose. Why use Java? Installing the Software. Java

ASSIGNMENT 5 Objects, Files, and More Garage Management

What s NetBeans? Like Eclipse:

Installing Eclipse (C++/Java)

CSCI 201 Lab 1 Environment Setup

Eclipse Environment Setup

16.410: Jump Starting With Java

Download and Installation Instructions. Eclipse Kepler Software for Windows

POOSL IDE Installation Manual

Hello Gradle. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Slide 1 CS 170 Java Programming 1 Duration: 00:00:49 Advance mode: Auto

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists

WA2009 Java EE 6 Programming - WebLogic 12c - Eclipse. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc.

S D K Q U I C K S T A R T

Hello Maven. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

WA2493 What's New in Java 8. Classroom Setup Guide. Web Age Solutions Inc.

Download and Installation Instructions. Eclipse Kepler Software for Mac OS X

Javadocing in Netbeans (rev )

Getting Started with the Bullhorn SOAP API and Java

Software Installation Guide

An Introduction to Ant

WA EJB and JPA Programming with Java EE 6 - WebLogic 12 / Eclipse. Classroom Setup Guide. Web Age Solutions Inc.

What is the Selendroid?

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

This example uses a Web Service that is available at xmethods.net, namely RestFulServices's Currency Convertor.

You will need to download the Java software development kit from

Embedding Graphics in JavaDocs (netbeans IDE)

Running Java Programs

You should now start on Chapter 4. Chapter 4 introduces the following concepts

Instructions. First, download the file

i2b2 Workbench Developer s Guide: Eclipse Neon & i2b2 Source Code

The ImageJ Eclipse Howto

Software Development Tools. COMP220/COMP285 Sebastian Coope Eclipse and JUnit: Creating and running a JUnit test case

- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

Welcome to Kmax Installing Kmax

Lecture (01) Getting started. Dr. Ahmed ElShafee

UNic Eclipse Mini Tutorial (Updated 06/09/2012) Prepared by Harald Gjermundrod

Life Without NetBeans

Using Eclipse and Karel

Department of Computer Science. Software Usage Guide. CSC132 Programming Principles 2. By Andreas Grondoudis

lejos NXJ Problem Solving with Robots [PRSOCO601]

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Before you start working with Java, you need to set up a Java development

Introduction to Eclipse

CSE 403 Lecture 11. Static Code Analysis. Reading: IEEE Xplore, "Using Static Analysis to Find Bugs"

WA day Java prereq for Selenium. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

Abstract. Avaya Solution & Interoperability Test Lab

Mehran Sahami Handout #5 CS 106A September 27, 2017 Downloading Eclipse

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

Setup and Getting Startedt Customized Java EE Training:

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

EUSurvey OSS Installation Guide

Module Road Map. 7. Version Control with Subversion Introduction Terminology

RTMS - Software Setup

Prerequisites for Eclipse

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

For live Java EE training, please see training courses at

RadBlue s S2S Quick Start Package (RQS) Developer s Guide. Version 0.1

Just Enough Eclipse What is Eclipse(TM)? Why is it important? What is this tutorial about?

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

Mehran Sahami Handout #5 CS 106A September 26, 2018 Downloading Eclipse

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

UNIVERSITY OF YORK. Service Builder. User Guide. Michael Weeks 4/1/2011

Chapter 1. Installation and Setup

Continuous Integration (CI) with Jenkins

This tutorial explains how you can use Gradle as a build automation tool for Java as well as Groovy projects.

COMP1007 Principles of Programming

Assignment 1. Application Development

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

BASIC USER TRAINING PROGRAM Module 1: Installation and Licensing

CLIF v2.3 Installation Manual

Installation Guide - Mac

WA2488 JavaScript Changes with ECMAScript Classroom Setup Guide. Web Age Solutions Inc.

CSC116: Introduction to Computing - Java

Table of Contents. 1 Introduction Downloads Eclipse SDK Installation Eclipse Workspace Eclipse Preferences...

Introduction to Computation and Problem Solving

Setting Up the Development Environment

Engr 123 Spring 2018 Notes on Visual Studio

Chapter Two Bonus Lesson: JavaDoc

Sample Spark Web-App. Overview. Prerequisites

Slide 1 Java Programming 1 Lecture 2D Java Mechanics Duration: 00:01:06 Advance mode: Auto

Transcription:

COMP220/285 Lab sessions 1-3 Contents General Notes... 2 Getting started... 2 Task 1 Checking your ANT install... 2 Task 2 Checking your JUnit install... 2 Task 3 JUnit documention review... 4 Task 4 Ant documention... 5 Task 5 Running the Eclipse IDE... 5 Selecting a workspace... 5 Starting with Eclipse... 6 Task 6 Creing a new Eclipse project... 6 Task 7 Eclipse and JUnit... 7 Task 8 Running a Simple Ant Build File... 7 Running JUnit and Ant on your personal or home computer... 11 COMP285/220 Page 1 of 14

General Notes Please work through the lab assignments in sequential order, so don t start a ler lab assignment until you have finished the earlier assignment. If you are not able to finish the all the tasks in the lab session, continue yourself in your own time. Notice within the lab work you will experience using Ant and JUnit as standalone tools as well as part of an integred environment such as Eclipse an ability for work in both contexts (standalone and IDE) is an important software engineering skill. This is because the power and complexity available by writing your own standalone scripts may not always be available from the IDE. Note, when running the example scripts, you can always copy and paste them from this document. Getting started Open a command prompt. Task 1 Checking your ANT install ant version You should see something like this (the actual version and build de may be different) M:\ ant -version Apache Ant(TM) version 1.10.1 compiled on February 2 2017 Task 2 Checking your JUnit install As part of the set up for the labs... you need to add the following classph, like so: Run this from the command prompt: set classph=%classph%;c:\java\junit4.12\hamcrest-core-1.3.jar; To just run JUnit with no tests, type the following java org.junit.runner.junitcore To run a set of example tests First copy this test class into your current directory http://cgi.csc.liv.ac.uk/~coopes/comp220/practical/exampletests.class and the type the following: java org.junit.runner.junitcore ExampleTests You should usually get the following (sometimes you will get test errors, see source code to find out why), run the a few times to see wh happens. COMP285/220 Page 2 of 14

JUnit version 4.12...I...I... Time: 0.02 OK (50 tests) Have a look the file ExampleTests.java (download code) and you can see the list of all the test cases. Each dot shows a test successfully executed. We can also see in the output the I this indices tests th are ignored (not actually run) Here is an example with a test th fails, not in this text there is an E in the output indicing a test has failed. JUnit version 4.12...I...E...I... Time: 0.03 There was 1 failure: 1) testf12(alltests) org.junit.comparisonfailure: expected:<[]ok> but was:<[not]ok> org.junit.assert.assertequals(assert.java:115) org.junit.assert.assertequals(assert.java:144) AllTests.testf12(Unknown Source) sun.reflect.nivemethodaccessorimpl.invoke0(nive Method) sun.reflect.nivemethodaccessorimpl.invoke(nivemethodaccessorimpl. java:62) sun.reflect.delegingmethodaccessorimpl.invoke(delegingmethodacces sorimpl.java:43) java.lang.reflect.method.invoke(method.java:483) org.junit.runners.model.frameworkmethod$1.runreflectivecall(framework Method.java:50) org.junit.internal.runners.model.reflectivecallable.run(reflectivecal lable.java:12) org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkme thod.java:47) org.junit.internal.runners.stements.invokemethod.evalue(invokemet hod.java:17) org.junit.runners.parentrunner.runleaf(parentrunner.java:325) org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrun ner.java:78) org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrun ner.java:57) org.junit.runners.parentrunner$3.run(parentrunner.java:290) org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) org.junit.runners.parentrunner.runchildren(parentrunner.java:288) COMP285/220 Page 3 of 14

org.junit.runners.parentrunner.access$000(parentrunner.java:58) org.junit.runners.parentrunner$2.evalue(parentrunner.java:268) org.junit.runners.parentrunner.run(parentrunner.java:363) org.junit.runners.suite.runchild(suite.java:128) org.junit.runners.suite.runchild(suite.java:27) org.junit.runners.parentrunner$3.run(parentrunner.java:290) org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) org.junit.runners.parentrunner.runchildren(parentrunner.java:288) org.junit.runners.parentrunner.access$000(parentrunner.java:58) org.junit.runners.parentrunner$2.evalue(parentrunner.java:268) org.junit.runners.parentrunner.run(parentrunner.java:363) org.junit.runner.junitcore.run(junitcore.java:137) org.junit.runner.junitcore.run(junitcore.java:115) org.junit.runner.junitcore.runmain(junitcore.java:77) org.junit.runner.junitcore.main(junitcore.java:36) FAILURES!!! Tests run: 50, Failures: 1 Note some tests may work on some test runs and not on others, for example if a test fails due to the timeout of a request the failure to run this test may be dependent on the current ste of the computer running the text. Task 3 JUnit documention review The document for JUnit should be http://junit.org/junit4/javadoc/lest/ Start your favourite browser and open and book mark the file. COMP285/220 Page 4 of 14

Task 4 Ant documention The Ant document is available https://ant.apache.org/manual/ Use the browser to review the documention. Task 5 Running the Eclipse IDE To start Eclipse do the following Start -> Java Apps -> Eclipse Note the actual Eclipse directory is C:\JAVA\eclipse The lest version of Eclipse will load, note th Eclipse is a large applicion and takes a while to load. Selecting a workspace A workspace is the running working area where all your projects are creed, edited, saved and built. You may be asked to select a workspace, if so pick your M: drive and cree a folder with a sensible name (e.g. M:\comp220\eclipse_projects). Note in the lab the workspace may have been preselected for you automically as M:\eclipse. Remember all the project work you are creing with Eclipse will be stored in this workspace directory, if you want to switch to a new workspace, you may do this by choosing File-> Workspace. To de (29/1/2018) the current version of Eclipse is called Oxygen Release (4.7.0) When you start Eclipse you will be presented with a screen as shown in Figure 1. COMP285/220 Page 5 of 14

Figure 1 Eclipse start up screen Starting with Eclipse Perspectives Likely as not, you will be presented with the Java perspective as shown in Figure 1, this shows you the menus and options suitable for Java development. You can switch perspective depending on the type of task you are involved with, for example you can change to the debug perspective by choosing Window-> Open Perspective-> Debug, try it and see how the display changes. Choose the correct perspective dependent on your task is important as it makes it easier to see wh is happening. Task 6 Creing a new Eclipse project Set the perspective back to Java. Choose File -> New -> Java Project and you should be presented with the window shown in Figure 2, choose a name for your project.. Example1 and then click Finish. COMP285/220 Page 6 of 14

Figure 2 Creing a project Now follow the steps outlined in lecture 6, to cree some new classes and build and execute your new project. Remember to follow the compulsory requirement to always include your student id within the package name. So if your student id, is 12345678, you package name should be something like this uk.ac.liv.csc.comp220.12345678 Task 7 Eclipse and JUnit In this task you will add a set of tests to your Eclipse project. Refer to the slides in lecture 8, Eclipse and JUnit. Now follow the step by step instruction in the slide, trying to repe (understand and remember) everything th was demonstred in the lectures. In particular you should start with the example project in the lecture notes, add the tests first following the test-first philosophy. Note for the lab test you may be asked to perform similar tasks and resolve similar issues, so practise these techniques so th you can complete the task quickly and accurely. Task 8 Running a Simple Ant Build File First cree a directory to store your build. mkdir buildexample1 Now add the following two files COMP285/220 Page 7 of 14

Main.java: public class Main { } public stic void main(string args[]) { for(int i=0;i<args.length;i++) { System.out.println(args[i]); } } build.xml: <?xml version="1.0"?> <project name="firstbuild" default="compile" > <target name="compile"> <javac srcdir="." includeantruntime="no"/> <!-- It is usually best to set includeantruntime to "false" or "no" so the script's behaviour is not sensitive to the environment in which it is run. See C:\JAVA\Ant1.8.1\docs\manual\index.html on <javac> task. --> <echo>compilion complete!</echo> </target> </project> Now run Ant from the current directory ant and look the Ant output, including the contents of the current directory. RUN Ant again. Do you see any difference? Try to understand wh it means and why. RUN Ant again with the content of Main.java changed trivially (say, by adding an unnecessary space and saving). Again, wh is the difference and how can it be explained? Wh if <javac> task in build.xml is misspelled, say, as <javaac>? RUN it, and after realizing wh happened recover build.xml back. COMP285/220 Page 8 of 14

RUN it with omitted the end tag </target> in build.xml and see wh is the effect. Do not forget to recover build.xml back. RUN it, with misspelled srcdir tribute as sourcedir in build.xml. Do not forget to recover build.xml back. If your build file has no errors, there may be errors because compiler fails how to compile your code. Delete the semicolon after println call in Main.java. RUN Ant. In this case build.xml is not responsible for BUILD FAILED. Do not forget to recover Main.java back again. The key point: failure of a single task halts the entire build resulting in BUILD FAILED. There is no point in packaging or delivering a project if it did not compile. Looking the build in more detail: TRY the command ant with verbose mode (twice when Main.class does already exist, and when it does not exist yet (or just deleted)) ant -verbose Wh is the difference? Pay tention to and explain these lines of the Ant output: ant -verbose... compile: [javac] Main.class skipped - don't know how to handle it [javac] Main.java omitted as Main.class is up to de.... COMP285/220 Page 9 of 14

The above was quite a simple laborory work. You should try to get a complete understanding. Ler the level of difficulty will increase as we will consider more complex tasks. COMP285/220 Page 10 of 14

Running JUnit and Ant on your personal or home computer Both JUnit and Ant are fairly easy to install and run on your home computer, but both rely on being configured correctly. Note these instructions are for machines running windows, but all these applicions will run just as well on Linux or Mac OS. Install a JDK SE To run Ant, you need to have Java installed. First check th you have the most recent Java JDK installed. Java JDK SE is available from Oracle www.oracle.com Download and install the JDK. Downloading and Installing ANT (Note work with lest versions, whever is written in this document) Ant is available from ant.apache.org/bindownload.cgi The current recommended version is 1.9.8, to download on Windows, pick the zip file, download and unzip, for Linux you may find the gz archive simpler to download and install. COMP285/220 Page 11 of 14

Once you have downloaded the Ant distribution, unzip it and copy the unzip the distribution file onto your machine, for the example given here, I unzipped the zip into root directory on C:, so looking on C: you can see the folder apache-ant-1.9.8 COMP285/220 Page 12 of 14

Downloading and installing JUnit JUnit is available (not current version is not 4.12) sourceforge.net/projects/junit/ The file you want is the zip file (for the jar file), the zip file contains all the Junit functionality plus some of the source code samples. When you have finished downloading JUnit, you should end up with a directory/folder like this, on your C: drive. COMP285/220 Page 13 of 14

Setting up phs and testing You now need to set up phs to get access to your JDK, Ant and JUnit directories and folders. On my machine, I have the script, shown in Figure 1, copied into a file called setph_ant_junit.b, download this script from the subject website. set ph=c:\program files\java \jdk1.7.0_10\bin;c:\apache-ant- 1.9.6\bin;%ph%; set classph=.;c:\program files\java \jdk1.7.0_10\bin\lib;c:\junit4.12;c: \junit4.12\junit-4.12.jar; set JAVA_HOME=c:\program files\java \jdk1.7.0_10 Once you have this script correct, open up a command prompt and run the script by just typing setph_ant_junit Make sure ant is working and runnable ant version Apache Ant(TM) version Make sure th Junit is working and runnable java org.junit.runner.junitcore JUnit version 4.12 Time: 0.002 OK (0 tests) If you get an error message from either of these two command, check the phs very carefully, you have probably something typed incorrectly in the script, check the script and your install folders and correct any ph errors. COMP285/220 Page 14 of 14