project beginning - cvut.cz

23
Project Beginning Martin Ledvinka [email protected] Winter Term 2020 Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 1 / 23

Upload: others

Post on 19-Oct-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Project Beginning - cvut.cz

Project Beginning

Martin Ledvinka

[email protected]

Winter Term 2020

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 1 / 23

Page 2: Project Beginning - cvut.cz

Contents

1 Deploy

2 Maven

3 Tasks

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 2 / 23

Page 3: Project Beginning - cvut.cz

Architecture

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 3 / 23

Page 4: Project Beginning - cvut.cz

Deploy

Deploy

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 4 / 23

Page 5: Project Beginning - cvut.cz

Deploy

WARWeb ArchiveFormat of deployable Java web application artefacts

EAR for full-blown Java EE artefacts

Figure : WAR structure. Source:https://docs.oracle.com/javaee/7/tutorial/packaging003.htm

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 5 / 23

Page 6: Project Beginning - cvut.cz

Deploy

WAR cont.

web.xml optional since Servlet API 3

All configuration can be done in source using Java + annotationsWe won’t be using it in our projects

WEB-INF is not part of the public document tree of the application

Not accessible by clientsBut accessible by servlet code – on classpathContains application code

lib for required libraries, e.g., Spring, JDBC driver

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 6 / 23

Page 7: Project Beginning - cvut.cz

Deploy

Deployment

The following applies to Apache Tomcat!

webapps folder for deployed web applications

Can deploy exploded WAR (unpacked)

Tomcat will otherwise unpack WARs automatically

Tomcat watches for changes in webappsCopy into folder – deployRemove WAR from folder – undeployApplication context

WAR file nameMETA-INF/context.xml in deployed WARcontext.xml in server configuration

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 7 / 23

Page 8: Project Beginning - cvut.cz

Deploy

Demo

Demo of servlet application from lecture one to Tomcat

Demo of servlet application from lecture one deployment in IntelliJIDEA via a Run configuration

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 8 / 23

Page 9: Project Beginning - cvut.cz

Maven

Maven

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 9 / 23

Page 10: Project Beginning - cvut.cz

Maven

Apache Maven

Software project management and comprehension tool

Manage project dependencies, build, reporting, documentation

Repository with libraries

Maven central at maven.org (Web UI athttp://search.maven.org)Possible to have own repository, see e.g.http://kbss.felk.cvut.cz/m2repoLocal repository – cache, in ${USER HOME}/.m2

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 10 / 23

Page 11: Project Beginning - cvut.cz

Maven

POM

Project Object Model

pom.xml file

Central XML-based configuration of Maven projectsHierarchical project identification

groupIdartifactIdversion

Manage dependencies – dependencies sectionManage build process – build section – using plugins – pluginssection

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 11 / 23

Page 12: Project Beginning - cvut.cz

Maven

Directory Structure

src/main

/java/resources/webapp

/test/java/resources

pom.xml

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 12 / 23

Page 13: Project Beginning - cvut.cz

Maven

Project Build Phases

1 validate - validate the project structure and configuration

2 compile - compile the source code of the project

3 test - test the compiled source code using a suitable testingframework

4 package - take the compiled code and package it in its distributableformat, such as a JAR

5 verify - run any checks on results of integration tests to ensurequality criteria are met

6 install - install the package into the local repository

7 deploy - copy the final package to the remote repository

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 13 / 23

Page 14: Project Beginning - cvut.cz

Maven

Dependency Scopes

compile – default, dependency available on classpath

provided – expected to be provided at runtime – by JDK,application server etc.

runtime – not required for compilation, but is for execution

test – required for test compilation and execution

system – similar to provided except that you have to provide theJAR which contains it explicitly. The artifact is always available andis not looked up in a repository.

import – used when specifying dependencies in parent projects

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 14 / 23

Page 15: Project Beginning - cvut.cz

Maven

Gradle

Maven GradleXML Groovy

Maven repo Maven repo

Plugins Plugins, direct code

Recompile everything on build Incremental build

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 15 / 23

Page 16: Project Beginning - cvut.cz

Tasks

Tasks

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 16 / 23

Page 17: Project Beginning - cvut.cz

Tasks

Task – Together

Inception of a Spring Boot project.

Spring Boot by default packaged as JAR

Use spring-boot-starter-parent Maven project parent toinherit dependencies easily

Various spring-boot-starter-* Maven projects pulling in groupsof related dependenciesspring-boot-starter-data-jpa for JPA, transaction APIspring-boot-starter-web for Jackson, Spring Web, MVC andembedded Tomcat

Build with spring-boot-maven-plugin to package dependeciesinto JAR automatically

We can use the SeminarTwoMain.java class to check that theJAR can be executed

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 17 / 23

Page 18: Project Beginning - cvut.cz

Tasks

Task – 1 point

1 Fork projecthttps://gitlab.fel.cvut.cz/ear/b201-eshop

2 Clone your fork of the B201-eshop project

3 Checkout branch b201-seminar-02-task

4 Create a Maven project using the HelloWorld.java,HelloWorldTest.java, and logback.xml files

Acceptance Criteria

Project has groupId, artifactId, name and description

Project can be packaged as WAR using Maven

Tests are run during build (and they pass)

When the resulting WAR is deployed to an application server (e.g.,Tomcat), the servlet is accessible through a web browser

Servlet access is logged based on the provided Logback configuration

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 18 / 23

Page 19: Project Beginning - cvut.cz

Tasks

Syncing Your Fork

1 Add upstream remote to the local clone of your fork

git remote add [email protected]:ear/b201-eshop.git

2 Fetch branches and commits from the upstream repository(EAR/B201-eshop)

git fetch upstream

3 Check out local branch corresponding to the task branch

git checkout -b b201-seminar-02-task

4 Merge changes from the corresponding upstream branch

git merge upstream/b201-seminar-02-task

5 Do your task6 Push the solution to your fork

git push origin b201-seminar-02-task

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 19 / 23

Page 20: Project Beginning - cvut.cz

Tasks

Task – Notes

You will need an application server for this task

For example, Apache Tomcat1 http://tomcat.apache.org/2 Download 9.0.383 Unpack4 Start by calling bin/startup.sh (Linux) or bin/startup.bat

(Windows)5 Deploy by copying WAR file into webapps directory

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 20 / 23

Page 21: Project Beginning - cvut.cz

Tasks

Task – Hints

Use Google or Maven central to find exact dependency identifiers

logback.xml should go into src/main/resources

Useful dependencies

SLF4J, Logback-classic

Servlet API (scope provided)

JUnit, Mockito-core (scope test)

Useful Maven plugins

Maven Compiler Plugin

Maven WAR Plugin

Maven Surefire Plugin

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 21 / 23

Page 22: Project Beginning - cvut.cz

Tasks

The End

Thank You

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 22 / 23

Page 23: Project Beginning - cvut.cz

Tasks

Resources

http://maven.apache.org/guides/

https://docs.oracle.com/javaee/7/tutorial/packaging003.htm

https://spring.io/guides/gs/spring-boot/

Martin Ledvinka ([email protected]) Project Beginning Winter Term 2020 23 / 23