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

IntelliJ IDEA – Cannot connect to the Maven process

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

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

Jersey and Jetty HTTP Server examples

This article shows how to start a Jetty HTTP Sever to run a JAX-RS or Eclipse Jersey application. Tested with Jersey 3.0.2 Jetty 11 Jackson 2.12.2 JUnit 5.4.0 (unit test) JSONassert 1.5.0 (unit test) Maven 3.8.3 Java 11 Tables of contents 1. Using Jersey with Jetty HTTP Server 2. Project Directory 3. Project dependencies 4. …

Read more

Maven + Quarkus Hello World example

This article shows how to use the quarkus-maven-plugin to create or scaffold a Maven + Quarkus JAX-RS hello world project. Technologies used: Quarkus 1.11.0 Maven 3.6.3 Java 11 Topics Creating a new Maven + Quartus project Maven + Quarkus Project Structure Quarkus and pom.xml Quarkus Dependencies Quarkus JAX-RX endpoint Quarkus and Dockerfile Run Quarkus in …

Read more

JUnit 5 Tagging and Filtering, @Tag examples

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

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

Java – How to enable the preview language features?

This article shows you how to use –enable-preview to enable the preview language features in Java 12, 13 and above. Note Read this JEP 12: Preview Language and VM Features P.S All preview features are disabled by default. On JDK 12: # compile javac Example.java // Do not enable any preview features javac –release 12 …

Read more

JUnit 5 + Maven examples

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

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

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

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

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

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

Spring Boot Hello World Example – JSP

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

Maven and JUnit example

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

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

Emma – Class x appears to be instrumented already

Review the “maven-emma-plugin” in pom.xml : pom.xml <project> //… <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0-alpha-3</version> <inherited>true</inherited> <executions> <execution> <phase>process-classes</phase> <goals> <goal>instrument</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <inherited>true</inherited> <configuration> <forkMode>once</forkMode> <reportFormat>xml</reportFormat> <classesDirectory> ${project.build.directory}/generated-classes/emma/classes </classesDirectory> </configuration> </plugin> </plugins> </build> </project> 1. Problem When I run the command mvn emma:emma to generate the code coverage report, …

Read more