Projet

Général

Profil

MAY Maven Eclipse Setup » Historique » Version 14

Anonyme, 24/10/2014 10:55

1 8 Anonyme
h1. MAY Maven Eclipse Setup
2 1 Anonyme
3 3 Anonyme
h2. Install the Maven Eclipse Plugin
4 1 Anonyme
5 3 Anonyme
The Maven Eclipse Plugin, also named M2E, is available as part of the normal Eclipse distribution but must be explicitly installed.
6
7
Go to *Help* / *Install New Software...* and select the *All available site* in the drop-down list (it may take some time to load).
8
9
Expand the *Collaboration* category and select *m2e - Maven Integration for Eclipse*.
10
11 4 Anonyme
Click *Next*, finish the installation procedure and restart Eclipse when asked to.
12 3 Anonyme
13
h2. Convert an Existing Project to Maven
14
15 1 Anonyme
The first step is to convert your project into a Maven project.
16
To do this, right click on your project and on *Configure* / *Convert to Maven Project*.
17
18 5 Anonyme
You will be asked to create a new POM file. Just click *Finish* after editing the package, name and version if desired.
19 3 Anonyme
20
Alternatively, you can directly create a Maven project, this is out of scope of this document.
21
22 12 Anonyme
h2. Maven and MAY
23 1 Anonyme
24 12 Anonyme
In Maven, the POM file (*pom.xml*, at the root of the project) contains information about the project and its dependencies.
25
By default, the POM file looks something like this:
26 11 Anonyme
<pre>
27 10 Anonyme
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
28
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
29 1 Anonyme
	<modelVersion>4.0.0</modelVersion>
30
	<groupId>XXX</groupId>
31
	<artifactId>XXX</artifactId>
32
	<version>XXX</version>
33
34
	<build>
35
		<sourceDirectory>src</sourceDirectory>
36
		<resources>
37
			<resource>
38
				<directory>src</directory>
39
				<excludes>
40
					<exclude>**/*.java</exclude>
41
				</excludes>
42
			</resource>
43
		</resources>
44
		<plugins>
45
			<plugin>
46
				<artifactId>maven-compiler-plugin</artifactId>
47
				<version>3.1</version>
48 7 Anonyme
				<configuration>
49
					<source>1.7</source>
50
					<target>1.7</target>
51
				</configuration>
52
			</plugin>
53 12 Anonyme
		</plugins>
54
	</build>
55
</project>
56
</pre>
57
58
In particular, it contains configurations to set the source directory or the compiler version.
59
60
Because MAY is a plugin that generates Java code from the SpeADL code in a separate folder, we need to tell Maven about this supplementary source folder with the following configuration:
61
<pre>
62
<project ...>
63
	...
64
	<build>
65
		...
66
		<plugins>
67
			...
68 9 Anonyme
			<!-- This configure maven to take into account the SpeADL code in the speadl-gen directory -->
69 7 Anonyme
			<plugin>
70 1 Anonyme
				<groupId>org.codehaus.mojo</groupId>
71
				<artifactId>build-helper-maven-plugin</artifactId>
72
				<version>1.8</version>
73
				<executions>
74
					<execution>
75
						<id>add-source</id>
76
						<goals>
77
							<goal>add-source</goal>
78
						</goals>
79
						<configuration>
80
							<sources>
81
								<source>speadl-gen</source>
82
							</sources>
83
						</configuration>
84
					</execution>
85
					<!-- The following is only needed so that speadl files are included 
86
						in the generated maven artifact -->
87
					<execution>
88
						<id>add-resource</id>
89
						<goals>
90
							<goal>add-resource</goal>
91
						</goals>
92
						<configuration>
93
							<resources>
94
								<resource>
95
									<directory>${project.build.sourceDirectory}</directory>
96
									<includes>
97
										<include>**/*.speadl</include>
98
									</includes>
99
								</resource>
100
							</resources>
101
						</configuration>
102
					</execution>
103
				</executions>
104
			</plugin>
105 12 Anonyme
			...
106 1 Anonyme
		</plugins>
107 12 Anonyme
		...
108
	</build>
109
</project>
110
</pre>
111
112
Apply this new configuration: right-click on the project *Maven / *Update Project...*, then select the project and click *Ok*.
113
114
h2. Maven and the MAY Component Library
115
116
With MAY, we provide a component library that we distribute through the Maven dependencies mechanism.
117
Any dependency specified in the POM file is automatically added to the classpath of the project and can be directly used.
118
119
In order to specify a dependency, it is needed to specify which version of the dependency is needed.
120
With the component library, the versioning follows the versioning of MAY for the first two digits and is specific to the library for the last one.
121
122
So for example, for MAY 3.4.X, one should use the component library 3.4.X.
123
124 13 Anonyme
Starting from version 3.4.X, the component library is available from "Maven Central":http://search.maven.org/#search|ga|1|g%3A%22fr.irit.smac.lib.may%22.
125
126
Before  that, it is needed to add the following repository to the requiring POM file:
127
<pre>
128
	<repositories>
129
		<repository>
130
			<id>fr.irit.smac</id>
131
			<url>http://www.irit.fr/~Victor.Noel/maven-repos/</url>
132
		</repository>
133
	</repositories>
134
</pre>
135
136 12 Anonyme
The following configuration adds the dependency to the POM file:
137
<pre>
138
<project ...>
139
	...
140
	<!-- We store the version of the component library in a property used later -->
141
	<properties>
142
		<may-lib-version>3.4.0</may-lib-version>
143
	</properties>
144
145
	<!-- We declare the dependency to the component library.
146
	         Its dependencies will be also be available. -->
147
	<dependencies>
148
		<dependency>
149
			<groupId>fr.irit.smac.lib.may</groupId>
150
			<artifactId>common-components</artifactId>
151
			<version>${may-lib-version}</version>
152
		</dependency>
153
	</dependencies>
154 1 Anonyme
155 13 Anonyme
	<!-- OPTIONAL: we declare the repository where the component library can be found -->
156 12 Anonyme
	<repositories>
157 14 Anonyme
		...
158 12 Anonyme
	</repositories>
159
	...
160
	<build>
161
	...
162 1 Anonyme
	</build>
163
</project>
164 11 Anonyme
</pre>
165 1 Anonyme
166
h2. Possible issues and resolutions
167
168 5 Anonyme
h3. Errors on the Project
169
170 1 Anonyme
You may get an error message saying your project configuration is out of date with your new pom.xml.
171
172 6 Anonyme
Update it: right click on your project *Maven* / *Update Project...* and click *Ok*.
173 5 Anonyme
174
h3. Errors in the POM File
175
176
You also may get an error saying the following in the POM file:
177
178
   Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source (execution: add-source, phase: generate-sources)
179
180
Click on *Discover new m2e connectors*, it should pre-check *buildhelper*, simply click *Finish* to accept and do the installation.