forked from fabienfelix/formation-programmation-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maven.html
120 lines (116 loc) · 10.2 KB
/
maven.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="author" content="Arnaud Tournier"><title>Introduction à Maven</title><meta content="yes" name="apple-mobile-web-app-capable"><meta content="black-translucent" name="apple-mobile-web-app-status-bar-style"><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" name="viewport"><link href="reveal.js/css/reveal.css" rel="stylesheet"><link rel="stylesheet" href="reveal.js/css/theme/beige.css" id="theme"><link href="reveal.js/lib/css/zenburn.css" rel="stylesheet"><script>document.write( '<link rel="stylesheet" href="reveal.js/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );</script></head><body><div class="reveal"><div class="slides"><section><h1>Introduction à Maven</h1><p><small>Arnaud Tournier</small></p></section><section><section id="_introduction_à_maven"><h2>Introduction à Maven</h2></section><section id="_qu_est_ce_que_maven"><h2>Qu’est-ce que Maven ?</h2><div class="paragraph"><p>Un outil qui sert à :</p></div>
<div class="ulist"><ul><li><p>Organisation des projets,</p></li><li><p>Compilation des projets,</p></li><li><p>Gestion des dépendances,</p></li><li><p>Tests unitaires, d’intégration, …​,</p></li><li><p>etc !</p></li></ul></div></section><section id="_le_pom"><h2>Le POM</h2><div class="paragraph"><p>Chaque projet Maven est défini dans un fichier <code>pom.xml</code>.</p></div>
<div class="paragraph"><p>Ce fichier est au format <code>xml</code>.</p></div>
<div class="paragraph"><p><a href="https://maven.apache.org/guides/introduction/introduction-to-the-pom.html">Introduction au modèle Maven</a>.</p></div></section><section id="_utilisation"><h2>Utilisation</h2><div class="paragraph"><p>Au lieu de créer nos projets dans Eclipse, nous allons déclarer dans un fichier <code>pom.xml</code> :</p></div>
<div class="ulist"><ul><li><p>l’identité de notre projet (GAV),</p></li><li><p>la liste des bibliothèques dont il dépend,</p></li><li><p>la façon dont on veut construire le projet.</p></li></ul></div>
<div class="paragraph"><p>Ensuite nous dirons à Eclipse d’utiliser les informations du <code>pom.xml</code> pour se configurer.</p></div></section><section id="_principe_fondamental"><h2>Principe fondamental</h2><div class="paragraph"><p>Nommage des <em>artefacts</em> par :</p></div>
<div class="ulist"><ul><li><p>un <em>groupId</em>,</p></li><li><p>un <em>artifactId</em>,</p></li><li><p>un numéro de <em>version</em>.</p></li></ul></div>
<div class="paragraph"><p>Ceci constitue le <em>GAV</em>.</p></div></section><section id="_allons_y"><h2>Allons-y !</h2><div class="paragraph"><p>Téléchargement de Maven ici :</p></div>
<div class="paragraph"><p><a href="https://maven.apache.org/download.html" class="bare">https://maven.apache.org/download.html</a></p></div></section><section id="_on_vérifie_la_version"><h2>On vérifie la version</h2><div class="literalblock"><div class="content"><pre>mvn --version</pre></div></div>
<div class="paragraph"><p>On obtient quelque chose comme :</p></div>
<div class="listingblock"><div class="content"><pre class="highlight"><code>Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: D:\apache-maven-3.0.5\bin\..
Java version: 1.8.0_25, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.8.0_25\jre
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 12", version: "6.1", arch: "amd64", family: "windows"</code></pre></div></div></section><section id="_création_d_un_projet"><h2>Création d’un projet</h2><div class="listingblock"><div class="content"><pre class="highlight"><code>mvn archetype:generate \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DgroupId=fr.lteconsulting.formation \
-DartifactId=exemple</code></pre></div></div>
<div class="paragraph"><p>Ceci crée un projet dans le sous-répertoire <code>exemple</code>.</p></div></section><section id="_la_structure_du_projet"><h2>La structure du projet</h2><div class="listingblock"><div class="content"><pre class="highlight"><code>exemple
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- fr
| `-- lteconsulting
| `-- exemple
| `-- App.java
`-- test
`-- java
`-- fr
`-- lteconsulting
`-- exemple
`-- AppTest.java</code></pre></div></div></section><section id="_"><div class="paragraph"><p><strong>Examinons le fichier <code>pom.xml</code>…​</strong></p></div></section><section id="_construction_du_projet"><h2>Construction du projet</h2><div class="paragraph"><p>Maven possède plusieurs <em>phases</em> de travail correspondant au cycle de vie de la construction du projet.</p></div>
<div class="literalblock"><div class="content"><pre>mvn package</pre></div></div>
<div class="paragraph"><p>Ceci déclenche l’exécution de la phase <em>package</em> qui va de la compilation à la génération de l’artéfact binaire (<code>jar</code> ou <code>war</code> par exemple).</p></div></section><section id="_lancement_du_projet"><h2>Lancement du projet</h2><div class="paragraph"><p>Avec la commande précédente, un fichier <code>jar</code> a été généré dans le répertoire <code>target</code>.</p></div>
<div class="paragraph"><p>On peut le lancer ainsi :</p></div>
<div class="literalblock"><div class="content"><pre>java -cp target/exemple-1.0-SNAPSHOT.jar fr.lteconsulting.exemple.App</pre></div></div></section><section id="_le_dépôt_local"><h2>Le dépôt local</h2><div class="paragraph"><p>Maven stocke l’ensemble des artifacts dont il s’est servi dans son <em>dépôt local</em>.</p></div>
<div class="paragraph"><p>Pour placer le résultat de notre compilation dans le dépôt local, lancer</p></div>
<div class="literalblock"><div class="content"><pre>mvn install</pre></div></div>
<div class="paragraph"><p>Allons voir le contenu du dépôt local dans <code>C:\Users\Moi\.m2</code>…​</p></div></section><section id="_génération_du_site_de_documentation"><h2>Génération du site de documentation</h2><div class="paragraph"><p>La commande :</p></div>
<div class="literalblock"><div class="content"><pre>mvn site</pre></div></div>
<div class="paragraph"><p>génèrera un site de documentation dans le sous-répertoire <code>target/site</code>.</p></div></section><section id="_les_phases"><h2>Les phases</h2><div class="paragraph"><p><a href="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html">Introduction</a></p></div></section></section></div></div><script src="reveal.js/lib/js/head.min.js"></script><script src="reveal.js/js/reveal.js"></script><script>// See https://github.com/hakimel/reveal.js#configuration for a full list of configuration options
Reveal.initialize({
// Display controls in the bottom right corner
controls: true,
// Display a presentation progress bar
progress: true,
// Display the page number of the current slide
slideNumber: false,
// Push each slide change to the browser history
history: true,
// Enable keyboard shortcuts for navigation
keyboard: true,
// Enable the slide overview mode
overview: true,
// Vertical centering of slides
center: true,
// Enables touch navigation on devices with touch input
touch: true,
// Loop the presentation
loop: false,
// Change the presentation direction to be RTL
rtl: false,
// Turns fragments on and off globally
fragments: true,
// Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen
embedded: false,
// Number of milliseconds between automatically proceeding to the
// next slide, disabled when set to 0, this value can be overwritten
// by using a data-autoslide attribute on your slides
autoSlide: 0,
// Stop auto-sliding after user input
autoSlideStoppable: true,
// Enable slide navigation via mouse wheel
mouseWheel: false,
// Hides the address bar on mobile devices
hideAddressBar: true,
// Opens links in an iframe preview overlay
previewLinks: false,
// Theme (e.g., beige, black, league, night, serif, simple, sky, solarized, white)
// NOTE setting the theme in the config no longer works in reveal.js 3.x
//theme: Reveal.getQueryHash().theme || 'beige',
// Transition style (e.g., none, fade, slide, convex, concave, zoom)
transition: Reveal.getQueryHash().transition || 'slide',
// Transition speed (e.g., default, fast, slow)
transitionSpeed: 'default',
// Transition style for full page slide backgrounds (e.g., none, fade, slide, convex, concave, zoom)
backgroundTransition: 'fade',
// Number of slides away from the current that are visible
viewDistance: 3,
// Parallax background image (e.g., "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'")
parallaxBackgroundImage: '',
// Parallax background size in CSS syntax (e.g., "2100px 900px")
parallaxBackgroundSize: '',
// The "normal" size of the presentation, aspect ratio will be preserved
// when the presentation is scaled to fit different resolutions. Can be
// specified using percentage units.
width: 960,
height: 700,
// Factor of the display size that should remain empty around the content
margin: 0.1,
// Bounds for smallest/largest possible scale to apply to content
minScale: 0.2,
maxScale: 1.5,
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});</script></body></html>