MAY Maven Eclipse Setup » Historique » Version 12
Anonyme, 20/10/2014 10:14
| 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 | The following configuration adds the dependency to the POM file: |
||
| 125 | <pre> |
||
| 126 | <project ...> |
||
| 127 | ... |
||
| 128 | <!-- We store the version of the component library in a property used later --> |
||
| 129 | <properties> |
||
| 130 | <may-lib-version>3.4.0</may-lib-version> |
||
| 131 | </properties> |
||
| 132 | |||
| 133 | <!-- We declare the dependency to the component library. |
||
| 134 | Its dependencies will be also be available. --> |
||
| 135 | <dependencies> |
||
| 136 | <dependency> |
||
| 137 | <groupId>fr.irit.smac.lib.may</groupId> |
||
| 138 | <artifactId>common-components</artifactId> |
||
| 139 | <version>${may-lib-version}</version> |
||
| 140 | </dependency> |
||
| 141 | </dependencies> |
||
| 142 | |||
| 143 | <!-- We declare the repository where the component library can be found --> |
||
| 144 | <repositories> |
||
| 145 | <repository> |
||
| 146 | <id>fr.irit.smac</id> |
||
| 147 | <url>http://www.irit.fr/~Victor.Noel/maven-repos/</url> |
||
| 148 | </repository> |
||
| 149 | </repositories> |
||
| 150 | ... |
||
| 151 | <build> |
||
| 152 | ... |
||
| 153 | 1 | Anonyme | </build> |
| 154 | </project> |
||
| 155 | 11 | Anonyme | </pre> |
| 156 | 1 | Anonyme | |
| 157 | h2. Possible issues and resolutions |
||
| 158 | |||
| 159 | 5 | Anonyme | h3. Errors on the Project |
| 160 | |||
| 161 | 1 | Anonyme | You may get an error message saying your project configuration is out of date with your new pom.xml. |
| 162 | |||
| 163 | 6 | Anonyme | Update it: right click on your project *Maven* / *Update Project...* and click *Ok*. |
| 164 | 5 | Anonyme | |
| 165 | h3. Errors in the POM File |
||
| 166 | |||
| 167 | You also may get an error saying the following in the POM file: |
||
| 168 | |||
| 169 | Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source (execution: add-source, phase: generate-sources) |
||
| 170 | |||
| 171 | Click on *Discover new m2e connectors*, it should pre-check *buildhelper*, simply click *Finish* to accept and do the installation. |