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 Emma – Class x appears to be instrumented already

This article shows how to fix the Maven error JAVA_HOME is not defined correctly. Terminal $ mvn -version Error: JAVA_HOME is not defined correctly. We cannot execute /usr/libexec/java_home/bin/java Further Reading How to set $JAVA_HOME environment variable on macOS 1. $JAVA_HOME and macOS 10.15 Catalina, macOS 11 Big Sur On macOS 10.15 Catalina and later, the […]

Read more Maven $JAVA_HOME is not defined correctly on Mac OS

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 How to create user defined properties in Maven

Problem Using Maven build tool, which jar should include to use HttpServletRequest or HttpServletResponse? Solution To use HttpServletRequest or HttpServletResponse in a development environment, include servlet-api. jar in your Maven pom.xml file. pom.xml <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> Put scope as provided, because most j2ee containers have this jar. You need this for complication […]

Read more Get HttpServletRequest via Maven repository

This tutorial will reuse and modify the previous Hibernate3.6 XML mapping tutorial, but replace the Hibernate mapping file (hbm) with Hibernate / JPA Annotation code. Technologies in this article : Maven 3.0.3 JDK 1.6.0_13 Hibernate 3.6.3.final Oracle 11g 1. pom.xml No change in pom.xml file, all previous Hibernate3.6 XML mapping tutorial dependency can be reused. […]

Read more Maven 3 + Hibernate 3.6 + Oracle 11g Example (Annotation)

In this article, we show you how to integrate Maven3, Hibernate3.6 and Oracle11g together. In the end of this article, you will create a Java project with Maven, and insert a record into Oracle database via Hibernate framework. Tools & technologies used in this article : Maven 3.0.3 JDK 1.6.0_13 Hibernate 3.6.3.final Oracle 11g 1. […]

Read more Maven 3 + Hibernate 3.6 + Oracle 11g Example (XML Mapping)

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging. 1. Maven Source Plugin Add maven-source-plugin in your pom.xml file. pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> […]

Read more Generate source code jar for Maven based project

The “maven-javadoc” plugin uses “JDK\bin\javadoc.exe” command to generate javadocs, pack in jar file and deploy along with your project. 1. Maven JavaDoc Plugin Add “maven-javadoc” plugin in your “pom.xml” file. File : pom.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>com.mkyong</groupId> <artifactId>mkyongcore</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>mkyongcore project</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-javadocs</id> <goals> […]

Read more Generate javadoc jar for Maven based project

Problem A pom.xml file, when “mvn site:deploy” is issued, the site doesn’t deploy to the defined server and hits the HTTP error code : 405. File : pom.xml <project …> <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-webdav-jackrabbit</artifactId> <version>1.0-beta-7</version> </extension> </extensions> </build> <distributionManagement> <site> <id>sitedeployment</id> <url>dav:http://127.0.0.1/upload-sites/</url> </site> </distributionManagement> </project> See full error message : D:\workspace-new\mkyong-core>mvn site:deploy [INFO] Scanning […]

Read more Maven + WebDAV – Embedded error: Failed to transfer file: … Return code is: 405

Here’s a guide to show you how to use “mvn site:deploy” to deploy your generated documentation site to server automatically, via WebDAV mechanism. P.S In this article, we are using Apache server 2.x with WebDAV enabled. 1. Enabled WebDAV See this guide to learn how to enable WebDAV access on Apache server 2.x. 2. Configure […]

Read more How to deploy site with “mvn site-deploy” – WebDAV example

During Eclipse development, it’s not practical to go outside of the Eclipse’s environment and execute Maven command in external console. In this article, we show you how to integrate Maven command with Eclipse IDE, via Eclipse’s “External Tool Configuration“. Normally, this external tool is used to run external command within Eclipse environment, and it works […]

Read more Integrate Maven with Eclipse via External Tool Configuration

In Maven, you can use “mvn site” to generate a documentation site for your project information. mvn site The generated site is under your project “target/site” folder. mvn site example See a list of files generated via “mvn site” command. A sample of documentation page. Note Personally, i do not like this feature much, because […]

Read more How to generate a documentation site for your Maven based project

In Maven, you can use “mvn install” to package your project and deploy to local repository automatically, so that other developers can use it. mvn install Note When “install” phase is executed, all above phases “validate“, “compile“, “test“, “package“, “integration-test“, “verify” phase , including the current “install” phase will be executed orderly. Refer to this […]

Read more How to install your project into Maven local repository

How do you know what is the available goals of a maven plugin, for example maven-eclipse plugin – mvn eclipse:goals?. In this article, we will show you how to display the entire goals of a Maven plugin. Plugin Documentation The best solution is Googling and visit the plugin documentation, for maven-eclipse, visit this maven-eclipse plugin […]

Read more How to display Maven plugin goals and parameters

In last tutorial, you created a Java project with Maven, but that project is not able to import into Eclipse IDE, because it is not Eclipse style project. Here’s a guide to show you how to convert the Maven generated Java project to Eclipse supported style project. 1. mvn eclipse:eclipse It’s really easy to do […]

Read more How to convert Maven based Java Project to support Eclipse IDE

Problem Maven as project build tool. Using Java generic function, when build with Maven, get this error message generics are not supported in -source 1.3 (use -source 5 or higher to enable generics) Solution You need to tell Maven to use JDK 1.5 to compile your source code explicitly. Declare Maven compiler plugin (maven-compiler-plugin) in […]

Read more Maven : generics are not supported in -source 1.3

Problem In Eclipse 3.5 or early version, in order to deployed the Maven dependencies to the correct “/WEB-INF/lib” folder, you have to configure the dependencies via “Java EE Module Dependencies”, and the updated “.classpath” file will look like following : File : “.classpath”, by Java EE Module Dependencies… … <classpathentry kind="var" path="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar" sourcepath="M2_REPO/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar"> <attributes> <attribute […]

Read more Eclipse : Web Deployment Assembly & Maven dependencies issue

Normally, when you use Maven command mvn eclipse:eclipse to convert existing Java project to support Eclipse project, Maven will create the entire dependency classpath by using the M2_REPO variable, which is not defined in Eclipse by default. Nothing special, M2_REPO is just a normal “classpath variable” in Eclipse to find your local Maven repository. Here, […]

Read more How to add M2_REPO classpath variable to Eclipse IDE

By default, Maven 2 uses JDK 1.4, Maven 3 uses JDK 1.5 to compile the project, which is very old. Fortunately, Maven comes with a Compiler Plugin, which tell Maven to compile the project source with a particular JDK version. Solution Configure the plugin compiler directly. (Tested with Maven 2 and 3) pom.xml <project> <build> […]

Read more How to compile Maven project with different JDK version?

The standard.jar (taglib) library is used to enable the JSTL expression language in JSP page, and it’s always used together with the jstl.jar together. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> …. </html> To download both standard.jar and jstl.jar from Maven, just put the following Maven coordinate in the pom.xml file. <!– standard.jar –> <dependency> <groupId>taglibs</groupId> […]

Read more Download standard.jar (taglib) from Maven

Problem By default, while starting the Tomcat server instance in Eclipse, the project’s dependency libraries will not deploy to the Eclipse’s Tomcat plugin library folder ‘WEB-INF/lib’ correctly. See this “.classpath” file, that is generated by Maven “mvn eclipse:eclipse” command. <classpath> <classpathentry kind="src" path="src/main/java" including="**/*.java"/> <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/> <classpathentry kind="output" path="target/classes"/> <classpathentry kind="var" path="M2_REPO/org/apache/struts/struts-core/1.3.10/struts-core-1.3.10.jar" /> […]

Read more Maven dependency libraries not deploy in Eclipse IDE

Download It – Spring-Hibernate-Annotation-Example.zip In last tutorial, you use Maven to create a simple Java project structure, and demonstrate how to use Hibernate in Spring framework to do the data manipulation works(insert, select, update and delete) in MySQL database. In this tutorial, you will learn how to do the same thing in Spring and Hibernate […]

Read more Maven + (Spring + Hibernate) Annotation + MySql Example

JavaMail is now available in Maven Central repository. pom.xml <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.6.2</version> </dependency> If you want to use the core JavaMail API to send email, you have to get the JavaMail library – mail.jar and activation.jar. Unfortunately, those libraries are not available in the Maven central repository, you have to download it from java.Net […]

Read more Maven – How to download JavaMail API