There is a project maven, when building a jar file is created that successfully displays the desired message. It is necessary that during the assembly passed the tests, what should be added to the xml file for this? Here is my xml

<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>Time</groupId> <artifactId>GreetTime</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>GreetJar</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.6</jdk.version> <log4j.version>1.2.12</log4j.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>src.java.main.Main</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib</classpathPrefix> <mainClass>Main</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> <scope>compile</scope> </dependency> </dependencies> 

A test.jar file is created.

  • for one mvn package to run tests? Is it possible to use mvn verify package? - Senior Pomidor
  • Launched, formed a new jar file, how does it differ from the past? And I added a maven-surefire-plugin it created Test.jar doesn’t it mean that my tests pass and run at build? - AlexanderBogomaz

1 answer 1

add to pom

  <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>false</skipTests> <excludes> <exclude>**/*IntegrationTest.java</exclude> </excludes> </configuration> <executions> <execution> <id>integration-test</id> <goals> <goal>test</goal> </goals> <phase>integration-test</phase> <configuration> <excludes> <exclude>none</exclude> </excludes> <includes> <include>**/*IntegrationTest.java</include> </includes> </configuration> </execution> </executions> </plugin> 

create class

  import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class IntegrationTest { @org.junit.Before public void setUp() throws Exception { System.out.println("setUp"); } @After public void tearDown() throws Exception { System.out.println("tearDown "); } @Test public void testfirst() throws Exception { System.out.println("testfirst"); } @Test public void testsecond() throws Exception { System.out.println("testsecond"); // Assert.fail(); } } 

run mvn clean verify package

 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ GreetTime --- [INFO] Building jar: C:\Users\\IdeaProjects\GreetJar\target\GreetTime-1.0.jar [INFO] [INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) @ GreetTime --- [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] Building jar: C:\Users\IdeaProjects\GreetJar\target\GreetTime-1.0-jar-with-dependencies.jar [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] [INFO] --- maven-surefire-plugin:2.10:test (integration-test) @ GreetTime --- [INFO] Surefire report directory: C:\Users\\IdeaProjects\GreetJar\target\surefire-reports ------------------------------------------------------- TESTS ------------------------------------------------------- Running IntegrationTest setUp testsecond tearDown setUp testfirst tearDown Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.11 sec Results : Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ GreetTime --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, ie build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ GreetTime --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ GreetTime --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, ie build is platform dependent! [INFO] skip non existing resourceDirectory IdeaProjects\GreetJar\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ GreetTime --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ GreetTime --- [INFO] Skipping execution of surefire because it has already been run for this configuration [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ GreetTime --- [INFO] [INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) @ GreetTime --- [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] Building jar: \IdeaProjects\GreetJar\target\GreetTime-1.0-jar-with-dependencies.jar [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [INFO] META-INF/ already added, skipping [INFO] META-INF/MANIFEST.MF already added, skipping [INFO] org/ already added, skipping [WARNING] Artifact Time:GreetTime:jar:jar-with-dependencies:1.0 already attached to project, ignoring duplicate [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.373s [INFO] Finished at: Sat Sep 17 13:40:45 MSK 2016 [INFO] Final Memory: 21M/265M [INFO] ------------------------------------------------------------------------ Process finished with exit code 0 
  • Thanks for the very informative answer. 1) I get [ERROR] Unable to locate the Javac Compiler in: C: \ Program Files \ Java \ jre1.8.0_101 \ .. \ lib \ tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). This is a java installation environment setting by JAVA_HOME environment variable. My JAVA_HOME is set up normally (2) After the clean command, the project does not start and you have to set it up with a new one. - AlexanderBogomaz
  • incorrectly configured environment variables. The answer to this question right here is at stackoverflow.com/questions/12585380/… see what they write on the Internet and how they decide not to spam here - Senior Pomidor