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

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

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

Maven resources folder is used to store all your project resources files like , xml files, images, text files and etc. The default Maven resources folder is located at “yourproject/src/main/resources“. Problem In some projects’ structure, the default resource folder may not suit in your needs, and an additional resource folder may required. Solution You can […]

Read more How to change Maven resources folder location?

If you want to include a library dependency in “pom.xml” file, you have to define the “Maven coordinate” <!– MySQL database driver –> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.9</version> </dependency> However, one of the annoying problem of this is you do not know what’s the Maven coordinate details – group id, artifactId and etc. Many Java developers […]

Read more How to search the Maven coordinates – pom.xml dependency?

In last tutorial, you created a web application with Maven. Here’s a guide to show you how to convert that web application to support Eclipse IDE. Note Eclipse IDE support web application via WTP tool, so you need to make your Maven based project support it as well. 1. mvn eclipse:eclipse -Dwtpversion=2.0 To convert a […]

Read more How to convert Maven based web application to support Eclipse IDE

Problem During the Eclipse debugging session, the “web.xml” will always deploy to a wrong folder. It’s always cause by manual migrated or converted a Java web project to Maven’s project. See the Eclipse’s workspace folder structure, Tomcat in Eclipse is deploy “web.xml” to a wrong folder, and causing the entire web application fail to run. […]

Read more Tomcat deploy Maven project web.xml to a wrong folder in Eclipse

Not every library is stored in the Maven Central Repository, some libraries are only available in Java.net or JBoss repository (remote repository). 1. Java.net Repository pom.xml <repositories> <repository> <id>java-net-repo</id> <url>https://maven.java.net/content/repositories/public/</url> </repository> </repositories> 2. JBoss Repository pom.xml <repositories> <repository> <id>jboss-repo</id> <url>http://repository.jboss.org/nexus/content/groups/public/</url> </repository> </repositories> 3. Spring Repository pom.xml <repositories> <repository> <id>spring-repo</id> <url>https://repo.spring.io/release</url> </repository> </repositories> References Configuring Maven […]

Read more How to add remote repository in Maven

Problem Building a Maven project, hit following annotation error message in Maven output console. [INFO] Compilation failure E:\workspace\serlvetdemo\src\main\java\com\mkyong\AppServletContextListener.java: [8,2] annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations) @Override Solution Maven default is using JDK1.3 for the project compilation, building or packaging (mvn compile, install). Since JDK1.3 is not […]

Read more Annotations are not supported in -source 1.3 – Maven

There is no exact or official solution to convert an existing Java web project to a Maven based web application project. Basically, the Maven based project conversion will involve two major changes, which is : Folder structure – Follow this Maven’s folder structure. Dependency library – Put all your dependency libraries in pom.xml file. Steps […]

Read more How to convert Java web project to Maven based project

Maven’s dependency mechanism help to download all the necessary dependency libraries automatically, and maintain the version upgrade as well. Case study Let see a case study to understand how it works. Assume you want to use Log4J as your project logging mechanism. Here is what you do… 1. In traditional way Visit http://logging.apache.org/log4j/ Download the […]

Read more Maven dependency mechanism, how it works

In this tutorial we will show you how to use mvn archetype:generate to generate a project from a list of existing Maven templates. In Maven 3.1.1, there are 1000+ templates, crazy, Maven team should filter out some useless templates. Normally, we just use the following two templates : maven-archetype-webapp – Java Web Project (WAR) maven-archetype-quickstart […]

Read more How to create a project with Maven template

Often times, you may to use “mvn eclipse:eclipse -Dwtpversion=1.5” command to create a web project for Eclipse IDE, but you may encounter the following error messages. Unsupported WTP version: 1.5. This plugin currently supports only the following versions: 1.0 R7 D:\mkyong>mvn eclipse:eclipse -Dwtpversion=1.5 [INFO] Scanning for projects… [INFO] Searching repository for plugin with prefix: ‘eclipse’. […]

Read more Unsupported WTP version: 1.5. This plugin currently supports only the following versions: 1.0 R7