The IntelliJ cannot find the mysql-connector-java dependency and hits error "unknown was not found"? pom.xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> Terminal mysql:mysql-connector-java:jar:unknown was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are […]

Read more mysql-connector-java: unknown was not found

This article shows how to generate the Maven Wrapper files in a Maven project: mvnw (For Linux or macOS) mvnw.cmd (For Windows) .mvn/wrapper/maven-wrapper.jar .mvn/wrapper/maven-wrapper.properties Table of contents 1. What is Maven Wrapper 2. Generate the mvnw and mvnw.cmd 2.1 Ensure Maven installed 2.2 Navigate to the Maven project 2.3 Generate Maven Wrapper files 2.4 Build […]

Read more How to generate Maven Wrapper files (mvnw and mvnw.cmd)

In the IntelliJ IDEA, clicks on the download sources, and it shows the error Cannot connect to the Maven process. Terminal Cannot connect to the Maven process. Try again later. If the problem persists, check the Maven Importing JDK settings and restart IntelliJ IDEA Tested with IntelliJ IDEA 2022.2.1 (Community Edition) Build #IC-222.3739.54, built on […]

Read more IntelliJ IDEA – Cannot connect to the Maven process

We upgraded the project from Java 11 to Java 17, and mvn test hits the Fatal error compiling: error: invalid target release: 17 pom.xml <properties> <java.version>17</java.version> </properties> Terminal mvn test [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project spring-boot-hello: Fatal error compiling: error: invalid target release: 17 -> [Help 1] The Java version is […]

Read more Maven error – invalid target release: 17

This article shows how to convert a Java project to a Maven project in IntelliJ IDEA. Table of contents 1. A Non-Maven Project 2. Add Framework Support – Maven 3. Update the default pom.xml 4. Reload the Maven project 5. References P.S Tested with IntelliJ IDEA 2021.1.1 1. A Non-Maven Project A non-Maven project (without […]

Read more Convert a Java project to Maven project in IntelliJ IDEA

This article shows you how to use the JUnit 5 tagging and filtering via the @Tag annotation. Tested with JUnit 5.5.2 Maven 3.6.0 Gradle 5.6.2 1. @Tag A simple tagging for demo. TagMethodTest.java package com.mkyong.tags; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @Tag("branch-20") public class TagMethodTest { @Test @Tag("feature-168") void test1Plus1() { assertEquals(2, 1 + […]

Read more JUnit 5 Tagging and Filtering, @Tag examples

Maven compiles and hits the following fatal error messages: Terminal mvn compile Fatal error compiling: error: invalid target release: 1.11 pom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.11</source> <target>1.11</target> </configuration> </plugin> Solution For maven-compiler-plugin, the correct JDK version is 1.8, 1.9, 1.10, 10, 11, 12 … 17 … pom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>11</source> <target>11</target> […]

Read more Maven error – invalid target release: 1.11

Maven compiles and hits the following maven-compiler-plugin error? The POM for org.apache.maven.plugins:maven-compiler-plugin:jar:3.8.1 is missing, no dependency information available pom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> Terminal > mvn compile [INFO] Scanning for projects… [INFO] [INFO] ——————–< com.mkyong.core:junit5-maven >——————– [INFO] Building junit5-maven 1.0 [INFO] ——————————–[ jar ]——————————— [WARNING] The POM for org.apache.maven.plugins:maven-compiler-plugin:jar:3.8.1 is […]

Read more Maven – The POM for maven-compiler-plugin:jar:3.8.1 is missing

This article shows you how to add JUnit 5 in a Maven project, nothing special, just add the JUnit 5 junit-jupiter-engine library and make sure the maven-surefire-plugin is at least version 2.22.0 Technologies used: Maven 3.6 Java 8 JUnit 5.5.2 1. Maven + JUnit 5 1. Add the JUni 5 jupiter engine. pom.xml <dependency> <groupId>org.junit.jupiter</groupId> […]

Read more JUnit 5 + Maven examples

In IntelliJ IDEA, Maven builds a project, and hits the following warning message? Warning:java: source value 1.5 is obsolete and will be removed in a future release Warning:java: target value 1.5 is obsolete and will be removed in a future release To fix it, add maven-compiler-plugin plugin. pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> […]

Read more Maven – source value 1.5 is obsolete and will be removed in a future release

In Maven, you can use Apache Maven Dependency Plugin, goal dependency:purge-local-repository to remove the project dependencies from the local repository, and re-download it again. Terminal $ mvn dependency:purge-local-repository [INFO] Scanning for projects… [INFO] [INFO] ————–< com.mkyong.examples:maven-code-coverage >————— [INFO] Building maven-code-coverage 1.0-SNAPSHOT [INFO] ——————————–[ jar ]——————————— [INFO] [INFO] — maven-dependency-plugin:2.8:purge-local-repository (default-cli) @ maven-code-coverage — Downloading from […]

Read more Maven – How to force re-download project dependencies?

In this article, we will show you how to use Maven PMD Plugin to analyze the Java code. P.S PMD requires Java 1.7 1. Maven PMD Plugin Define the maven-pmd-plugin in the reporting tag, so that mvn site will generate the PMD report. pom.xml <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.11.0</version> </plugin> </plugins> </reporting> 2. Java […]

Read more Maven – PMD example

Generating a Maven report with mvn site, but hits the following errors java.lang.NoClassDefFoundError: org/apache/maven/doxia/siterenderer/DocumentContent Caused by: java.lang.ClassNotFoundException: org.apache.maven.doxia.siterenderer.DocumentContent [INFO] ———————————————————————— [INFO] BUILD FAILURE [INFO] ———————————————————————— [INFO] Total time: 28.280 s [INFO] Finished at: 2018-11-19T13:20:14+08:00 [INFO] ———————————————————————— [ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project maven-static-code-analysis: Execution default-site of goal org.apache.maven.plugins:maven-site-plugin:3.3:site failed: A required class […]

Read more mvn site : java.lang.ClassNotFoundException: org.apache.maven.doxia.siterenderer.DocumentContent

In this article, we will show you few Maven profile examples to pass different parameters (server or database parameters) for different environments (dev, test or prod). P.S Tested with Maven 3.5.3 1. Basic Maven Profiles 1.1 A simple profile to skip the unit test. pom.xml <!– skip unit test –> <profile> <id>xtest</id> <properties> <maven.test.skip>true</maven.test.skip> </properties> […]

Read more Maven Profiles example

In this tutorial, we will show you how to use Maven to manage a Multi-module project containing four modules : Password module – Interface only. Password md5 module – Password module implementation, MD5 password hashing. Password sha module – Password module implementation, SHA password hashing. Web module – A simple MVC web app to hash […]

Read more Maven – How to create a multi module project

Maven compile a project in Eclipse IDE, but hits the following error messages : $ mvn clean compile [ERROR] COMPILATION ERROR : [INFO] ————————————————————- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ————————————————————- [INFO] ———————————————————————— [INFO] BUILD FAILURE [INFO] ———————————————————————— […]

Read more Eclipse IDE – No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

In Maven, you can use mvn help:effective-pom to list all the current project’s plugins and its version. D:\maven-examples\java-web-project> mvn help:effective-pom [INFO] Scanning for projects… [INFO] [INFO] ——————< com.mkyong.web:java-web-project >——————- [INFO] Building java-web-project Maven Webapp 1.0-SNAPSHOT [INFO] ——————————–[ war ]——————————— [INFO] [INFO] — maven-help-plugin:3.1.0:effective-pom (default-cli) @ java-web-project — [INFO] Effective POMs, after inheritance, interpolation, and profiles […]

Read more Maven – List all the project’s plugins

In pom.xml, defined this maven.compiler.source properties to tell Maven to use Java 8 to compile the project. 1. Maven Properties Java 8 pom.xml <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties> Java 7 pom.xml <properties> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.source>1.7</maven.compiler.source> </properties> 2. Compiler Plugin Alternative, configure the plugin directly. pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> […]

Read more How to tell Maven to use Java 8

A Spring Boot web application example, using embedded Tomcat + JSP template, and package as an executable WAR file. Technologies used : Spring Boot 1.4.2.RELEASE Spring 4.3.4.RELEASE Tomcat Embed 8.5.6 Maven 3 Java 8 1. Project Directory Create the following folders manually : 2. Project Dependencies Maven example. Read comments for self-explanatory. pom.xml <?xml version="1.0" […]

Read more Spring Boot Hello World Example – JSP

In Maven, you can declare the JUnit dependency like this: pom.xml <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> But, it comes with a bundled copy of hamcrest-core library. $ mvn dependency:tree … [INFO] \- junit:junit:jar:4.12:test [INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test … 1. Maven + JUnit + Hamcrest Note Not a good idea to use the default […]

Read more Maven and JUnit example

Maven package a web application and hits the following error message : $ mvn package //… [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring4-mvc-maven-ajax-example: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1] Solution 1. For servlet container < 3, make sure WEB-INF/web.xml file […]

Read more Maven – webxml attribute is required

Few Maven Jetty 8.x and 9.x plugin examples, just for quick reference. 1. Maven Jetty Plugin 9.x Note You need to use Maven 3 and Java 1.7 for Maven Jetty 9.x plugin. 1.1 The ‘groupId’ is org.eclipse.jetty, by default, it runs on port 8080, in root context ‘/’. pom.xml <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.2.11.v20150529</version> </plugin> To […]

Read more Maven Jetty Plugin Examples

In Maven, you can use mvn dependency:tree to display the project dependencies in tree format. 1. Maven Project Review a simple Maven project, declared Spring and logback dependencies. pom.xml <properties> <spring.version>4.1.6.RELEASE</spring.version> <logback.version>1.1.3</logback.version> <jcl.slf4j.version>1.7.12</jcl.slf4j.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>${jcl.slf4j.version}</version> […]

Read more Maven – Display project dependency

This example shows you how to use Maven to exclude the log4j.properties file from your Jar file. Note Please, DO NOT include the log4j.properties into the final Jar file, it will cause multiple log4j.properties files in the classpath, if someone is depending on your Jar, you may accidentally override their logging configurations, depends which Jar […]

Read more Maven – Exclude log4j.properties in Jar file

Creating a Maven site, but the build is very slow to generate the dependency report. C:\mkyong_projects\>mvn site [INFO] Scanning for projects… [INFO] [INFO] ————————————– [INFO] Building Maven Webapp 1.0-SNAPSHOT [INFO] ————————————– [INFO] //… [INFO] Generating "Project License" report [INFO] Generating "Project Team" report [INFO] Generating "Project Summary" report [INFO] Generating "Dependencies" report //…… Hanging here… […]

Read more Maven site build is very slow – dependency report