mysql-connector-java: unknown was not found

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

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

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

Maven error – invalid target release: 17

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: 1.11

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 – The POM for maven-compiler-plugin:jar:3.8.1 is missing

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 – source value 1.5 is obsolete and will be removed in a future release

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 – How to force re-download project dependencies?

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 – PMD example

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

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

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

Maven – JaCoCo code coverage example

In this article, we will show you how to use a JaCoCo Maven plugin to generate a code coverage report for a Java project. Tested with Maven 3.5.3 JUnit 5.3.1 jacoco-maven-plugin 0.8.2 Note JaCoCo is an actively developed line coverage tool, that is used to measure how many lines of our code are tested. 1. …

Read more

Maven Profiles example

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 – How to create a multi module project

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 test failed on Spring @Autowired and jUnit 5

Review the following jUnit 5 examples to test a Spring 5 MVC web application. TestWelcome.java package com.mkyong.web; import com.mkyong.web.config.SpringConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = …

Read more

No more mvn eclipse:eclipse, what’s next?

The Apache Maven Eclipse Plugin is retired, no more following commands # support eclipse ide $ mvn eclipse:eclipse # web project $ mvn eclipse:eclipse -Dwtpversion=2.0 What is the equivalent in Eclipse IDE? 1. Solution Please use Eclipse Maven Integration (m2e). Latest Eclipse IDE has bundled the m2e plugin : 2. How to use m2e? The …

Read more

Maven – List all the project’s plugins

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

How to tell Maven to use Java 8

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

Maven – Deploy web application to WildFly

In Maven, we can use the official JBoss WildFly Maven Plugin to deploy a web application (war file) to the WildFly application server. Technologies tested : Maven 3.3.9 WildFly 9.0.2.final WildFly Maven Plugin 1.1.0.Alpha5 P.S This Spring MVC web application will be used for this deployment test. 1. Deploy WAR To WildFly 1.1 Start WildFly …

Read more

Maven – webxml attribute is required

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

Jetty – java.net.BindException: Address already in use

Start a Java webapp with Maven Jetty plugin. $ mvn jetty:run 1. Problem But it hits the following error messages : [WARNING] FAILED org.eclipse.jetty.maven.plugin.JettyServer@1f53481b: java.net.BindException: Address already in use at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) //… 2. Solution By default, the maven-jetty-plugin start Jetty on port …

Read more

Maven Jetty Plugin Examples

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 – Display project dependency

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 – Get source code for Jar

In Maven, you can get source code for project dependencies in most IDEs like this : $ mvn dependency:sources $ mvn dependency:resolve -Dclassifier=javadoc Get source code for Jar Get javadoc for Jar, normally, developers don’t provide this. 1. Eclipse IDE In Eclipse IDE, it’s better to use the maven eclipse plugin: $ mvn eclipse:eclipse -DdownloadSources=true …

Read more

Create a fat Jar file – Maven Assembly Plugin

In this tutorial, we will show you how to create a fat/uber jar with Maven Assembly Plugin. Which means create a Jar together with its dependency Jars into a single executable Jar file. Note Maven assembly plugin is not good in producing fat/uber jar, it may cause name conflict issue, it is better to use …

Read more

Maven – Exclude log4j.properties in Jar file

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

Create a fat Jar file – Maven Shade Plugin

In this tutorial, we will show you how to use Maven Shade Plugin to create a Jar together with its dependency Jars into a single executable Jar file, so called fat Jar or uber Jar. Note Maven Shade plugin is a better plugin to create fat/uber jar, if compare with assembly plugin, because it provides …

Read more

Maven – Exclude logback.xml in Jar file

This example shows you how to use Maven to exclude the logback.xml file from the final Jar file. Note Please, DO NOT include the logback.xml into the final Jar file, it will cause multiple logback.xml files in the classpath, if someone is using your Jar, you may override other’s logging configurations accidentally. pom.xml <project> <build> …

Read more

Maven + Emma code coverage example

Emma is a free Java code coverage tool. In this tutorial, we will show you how to use Maven to generate the Emma code coverage report for your project, and also how to integrate the Emma report into the Maven project site. 1. Generate Emma Code Coverage Report Do nothing, just type the following Maven …

Read more

Maven site build is very slow – dependency report

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

How to create a manifest file with Maven

This tutorial will show you how to use the maven-jar-plugin to create a manifest file, and package / add it into the final jar file. The manifest file is normally used to define following tasks : Define the entry point of the Application, make the Jar executable. Add project dependency classpath. When you run the …

Read more

How to create a jar file with Maven

In this tutorial, we will show you how to use Maven build tool, to create a single executable Jar, and how to deal with the project’s dependencies. Tools used : Maven 3.1.1 JDK 1.7 log4j 1.2.17 Joda-time 2.5 Eclipse 4.3 1. Create a simple Java project Create a Java project from the Maven quick start …

Read more

How to create user defined properties in Maven

Custom properties or variables are useful to keep your Maven pom.xml file more easy to read and maintain. File : pom.xml <project> … <properties> <my.plugin.version>1.5</my.plugin.version> </properties> … </project> In above pom.xml, you can refer “my.plugin.version” via code ${my.plugin.version}. Example 1 A classic use case is used to define a jar or plugin version. <properties> <spring.version>3.1.2.RELEASE</spring.version> …

Read more

Eclipse code assist in Maven pom.xml

By default, code assist in editing a pom.xml is NOT supported in Eclipse IDE. It make Maven project hard to maintain, and who will remember who all those tags? Solution You need a pom.xml Maven editor, which is available in m2eclipse plugin. In Eclipse, menu, select “Help” -> “Install New Software”, and put following m2eclipse …

Read more