Skip to content
Snippets Groups Projects
Commit cb3dc091 authored by Joel Cavat's avatar Joel Cavat
Browse files

First commit

parents
Branches
No related tags found
No related merge requests found
target
# Maven
Maven est un gestionnaire de projets et d'automatisation de production pour l'écosystème Java.
Le fichier `pom.xml` décrit le projet avec ses dépendances.
### Modification du fichier pom.xml
Adaptez le fichier `pom.xml` selon votre projet :
- Verifiez la version de java
- Changez le nom du projet/package dans `groupId` et `artifactId`
- Modifiez la configuration du plugin `exec-maven-plugin` pour pointer sur votre classe principale contenant votre `main`
### Exécutez votre projet
- compilation et téléchargement des dépendances. Produit un `jar` dans le dossier `target`.
```
mvn package
```
- exécutez à l'aide de java et du classpath:
```
java -cp target/my-app-0.1.jar ch.hepia.my_app.App
```
- ou, à l'aide du plugin `exec-maven-plugin`:
```
mvn exec:java
```
### Exécutez les tests uniquement
```
mvn test
```
### Notes
Le plugin `maven-assembly-plugin` est configuré et permet d'embarquer les dépendances dans un seul `jar`.
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.hepia.my_app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>my-app</name>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Point here to your main class -->
<mainClass>ch.hepia.my_app.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<excludes>
<exclude>some test to exclude here</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package ch.hepia.my_app;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
package ch.hepia.my_app;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* Unit test for simple App.
*/
class AppTest {
@Test
void dummyTest() {
assertTrue(true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment