Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 305 Individual Software Design and Development Lecture 04. Dependency Management

Slide 2

Slide 2 text

Previously … 2

Slide 3

Slide 3 text

Previously …

Slide 4

Slide 4 text

Previously … 4

Slide 5

Slide 5 text

Dependencies

Slide 6

Slide 6 text

Library • A collection of resources (cl a sses) • A J a v a Archive, or JAR f ile, cont a ins a ll of the v a rious components th a t m a ke up a self- cont a ined, execut a ble J a v a a pplic a tion or, most commonly, a J a v a libr a ry to which a J a v a Runtime Environment c a n link. 6

Slide 7

Slide 7 text

jar-download.com 7

Slide 8

Slide 8 text

• Build m a n a gement tool • M a ven a utom a tes dependency m a n a gement by a utom a tic a lly downlo a ding required libr a ries a nd their dependencies, ensuring consistent builds with speci f ied versions. • In contr a st, m a nu a lly downlo a ding JARs is l a bor-intensive a nd error-prone. 8

Slide 9

Slide 9 text

• The project object model (POM) f ile describes a project a nd its dependencies. • A st a nd a rdized directory form a t. • Repositories where third-p a rty softw a re is stored a nd discovered. 9

Slide 10

Slide 10 text

Maven File and Directories 10

Slide 11

Slide 11 text

Maven

Slide 12

Slide 12 text

Create a project with Maven support 12

Slide 13

Slide 13 text

POM.xml 13

Slide 14

Slide 14 text

Maven Repository 14

Slide 15

Slide 15 text

Adding a New Dependency 15

Slide 16

Slide 16 text

Right-Click POM.xml 16

Slide 17

Slide 17 text

Jsoup Java HTML Parser

Slide 18

Slide 18 text

Jsoup • A J a v a libr a ry th a t simpli f ies working with HTML a nd XML. • O ff ers URL fetching, d a t a p a rsing, extr a ction, a nd m a nipul a tion. • https://jsoup.org/ 18

Slide 19

Slide 19 text

MVN Repository 19

Slide 20

Slide 20 text

Load Maven Changes 20

Slide 21

Slide 21 text

Jsoup Example 21

Slide 22

Slide 22 text

https://github.com/CSC3100/Maven 22 https://github.com/CSC3100/Tool-Maven

Slide 23

Slide 23 text

We need to talk about the Factory Pattern Pattern 23

Slide 24

Slide 24 text

JavaParser A Parser for Java Code

Slide 25

Slide 25 text

JavaParser • A J a v a libr a ry to a n a lyze, tr a nsform, a nd gener a te J a v a code. • https://j a v a p a rser.org/ 25

Slide 26

Slide 26 text

MVN Repository 26

Slide 27

Slide 27 text

Load Maven Changes 27

Slide 28

Slide 28 text

JavaParser Example 28

Slide 29

Slide 29 text

https://github.com/CSC3100/Maven 29 https://github.com/CSC3100/Tool-Maven

Slide 30

Slide 30 text

We need to talk about the Null Object Pattern Pattern 30

Slide 31

Slide 31 text

JFreeChart Display Charts

Slide 32

Slide 32 text

JFreeChart • https://www.jfree.org/jfreech a rt/ • JFreeCh a rt is a libr a ry to displ a y profession a l-qu a lity ch a rts. 32

Slide 33

Slide 33 text

MVN Repository 33

Slide 34

Slide 34 text

Load Maven Changes 34

Slide 35

Slide 35 text

JFreeChart Example 35

Slide 36

Slide 36 text

https://github.com/CSC3100/Maven 36 https://github.com/CSC3100/Tool-Maven

Slide 37

Slide 37 text

Another appearance of the Factory Pattern Pattern 37

Slide 38

Slide 38 text

Weka Machine Learning

Slide 39

Slide 39 text

Weka • Wek a is a collection of m a chine le a rning a nd d a t a a n a lysis • W a ik a to Environment for Knowledge An a lysis (Wek a ) • developed a t the University of W a ik a to, New Ze a l a nd • https://ml.cms.w a ik a to. a c.nz/wek a • 39

Slide 40

Slide 40 text

MVN Repository 40

Slide 41

Slide 41 text

Load Maven Changes 41

Slide 42

Slide 42 text

Step 1: Create Instances 42

Slide 43

Slide 43 text

Step 1: Or Load Instances 43

Slide 44

Slide 44 text

Step 2. Clustering 44

Slide 45

Slide 45 text

https://github.com/CSC3100/Maven 45 https://github.com/CSC3100/Tool-Maven

Slide 46

Slide 46 text

MQTT Message Queuing

Slide 47

Slide 47 text

Pong 47 https://github.com/CSC3100/Pong-Game

Slide 48

Slide 48 text

Eclipse Paho for Java Wh a t is Eclipse P a ho? • A set of MQTT client libr a ries developed by the Eclipse Found a tion. • It supports multiple l a ngu a ges, such a s J a v a , Python, J a v a Script, etc. J a v a Dependency (M a ven) org.eclipse.paho org.eclipse.paho.client.mqttv3 1.2.5 48

Slide 49

Slide 49 text

https://github.com/CSC3100/MQTT

Slide 50

Slide 50 text

https://github.com/CSC3100/MQTT

Slide 51

Slide 51 text

We need to talk about the Publisher-Subscriber Pattern Pattern 51

Slide 52

Slide 52 text

JDBC SQL Database

Slide 53

Slide 53 text

Key Idea 53 ⚙

Slide 54

Slide 54 text

www.freesqldatabase.com 54

Slide 55

Slide 55 text

Dependencies 55

Slide 56

Slide 56 text

Connection 56

Slide 57

Slide 57 text

SQL Statements 57

Slide 58

Slide 58 text

We need to talk about Standard Solutions Pattern 58

Slide 59

Slide 59 text

Logging

Slide 60

Slide 60 text

Problem 60

Slide 61

Slide 61 text

Problem 61

Slide 62

Slide 62 text

Bad Idea System.out.println 62 Messages

Slide 63

Slide 63 text

Logging • Recording events, a ctions, or mess a ges th a t occur during the execution of a progr a m. • Proper logging is essenti a l for m a int a ining a nd troubleshooting a pplic a tions e ff ectively throughout their lifecycle. 63

Slide 64

Slide 64 text

Good Idea 64 message 01 message 02 message 03 message 04 message 05

Slide 65

Slide 65 text

SLF4J Logback • St a nds for Simple Logging F a c a de for J a v a • It provides a uni f ied interf a ce for logging oper a tions, a llowing developers to write logging code without binding their a pplic a tion to a speci f ic logging implement a tion. • We need to t a lk a bout the F a c a de P a ttern 65

Slide 66

Slide 66 text

Getting Started

Slide 67

Slide 67 text

SLF4J Logback | Add the dependency 67 https://github.com/CSC3100/Tool-Logging

Slide 68

Slide 68 text

SLF4J Logback | Logging 68 https://github.com/CSC3100/Tool-Logging

Slide 69

Slide 69 text

SLF4J Logback | Logging 69 https://github.com/CSC3100/Tool-Logging

Slide 70

Slide 70 text

Severity Level 70 TRACE DEBUG INFO WARN ERROR Severity

Slide 71

Slide 71 text

We want this 71 message 01 message 02 message 03 message 04 message 05 trace() debug() info () warn () error() Logger 71

Slide 72

Slide 72 text

To be continued…

Slide 73

Slide 73 text

Maven File and Directories 73

Slide 74

Slide 74 text

Resources Folder • The resources folder in a M a ven project stores non-source-code f iles th a t your a pplic a tion needs, such a s con f igur a tion f iles, property f iles, im a ges, a nd other resources. • These f iles a re included in the f in a l build output a nd a v a il a ble on the cl a ssp a th a t runtime. 74

Slide 75

Slide 75 text

src/main/resources/logback.xml • logb a ck.xml is a con f igur a tion f ile for SLF4J Logb a ck. • It de f ines how logging should be h a ndled, including log levels, a ppenders (where logs a re written), a nd log form a ts. • When your a pplic a tion st a rts, SLF4J Logb a ck a utom a tic a lly looks for this con f igur a tion f ile. 75

Slide 76

Slide 76 text

ConsoleAppender 76 message 01 message 02 message 03 message 04 message 05 trace() debug() info () warn () error() Logger 76 Appender

Slide 77

Slide 77 text

src/main/resources/logback.xml 77 https://github.com/CSC3100/Tool-Logging

Slide 78

Slide 78 text

SLF4J Logback | Logging 78

Slide 79

Slide 79 text

ConsoleAppender 79 message 01 message 02 message 03 message 04 message 05 trace() debug() info () warn () error() Logger 79 Appender

Slide 80

Slide 80 text

Encoder

Slide 81

Slide 81 text

Logstash Logback Encoder | POM.xml • Let’s use a nother libr a ry to t a ke a dv a nt a ge of extr a encoders • form a t Spring Boot logs in JSON form a t 81 https://github.com/CSC3100/Tool-Logging

Slide 82

Slide 82 text

src/main/resources/logback.xml 82 https://github.com/CSC3100/Tool-Logging

Slide 83

Slide 83 text

SLF4J Logback | Logging 83

Slide 84

Slide 84 text

FileAppender

Slide 85

Slide 85 text

Next 85 trace() debug() info () warn () error() message 01 message 02 message 03 message 04 message 05 Logger Appender Appender

Slide 86

Slide 86 text

src/main/resources/logback.xml 86 https://github.com/CSC3100/Tool-Logging

Slide 87

Slide 87 text

SLF4J Logback | Logging 87

Slide 88

Slide 88 text

Questions 88

Slide 89

Slide 89 text

Lab 04. Maven

Slide 90

Slide 90 text

Create a Maven Project on your IDE Lab 90

Slide 91

Slide 91 text

Download and Run on Your computer: https://github.com/CSC3100/Tool-Maven Lab 91

Slide 92

Slide 92 text

CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D. [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.