Maven M2_REPO is non modifiable

Problem Forgot what i did, may be installed m2eclipse plguin, it made the M2_REPO classpath variable is unable to edit. Select Windows -> Preferences -> Java -> Build Path -> Classpath Variables. Eclipse come with embedded Maven and have this M2_REPO classpath variable default non modifiable also. Figure – M2_REPO is non modifiable Solution To …

Read more

Maven 3 need to know the plugin version

In Maven 2, if you didn’t specify the version for each plugins that used in pom.xml, it will pick the latest plugin version automatically, which is very convenient. However, in Maven 3, if you didn’t explicitly specify the plugin version, it will prompt you warning message. Read this “Maven 3 compatibility” for detail. For example, …

Read more

Get HttpServletRequest via Maven repository

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

How to add Oracle JDBC driver in your Maven local repository

Here’s a simple guide to show you how to add an Oracle JDBC driver into your Maven local repository, and also how to reference it in pom.xml Tested with Oracle database 19c and Java 8 Note Due to Oracle license restrictions, the Oracle JDBC driver is not available in the public Maven repository. To use …

Read more

Generate source code jar for Maven based project

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

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

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

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

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

Integrate Maven with Eclipse via External Tool Configuration

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

How to deploy Maven based war file to Tomcat

In this tutorial, we will show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat, both in Tomcat 6 and 7. Libraries used : Maven 3 Tomcat 6.0.37 Tomcat 7.0.53 Tomcat 7 Deploy URL = http://localhost:8080/manager/text Command = mvn tomcat7:deploy Tomcat 6 Deploy URL = http://localhost:8080/manager/ Command = mvn …

Read more

How to generate a documentation site for your Maven based project

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 install your project into Maven local repository

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 clean project with Maven

In Maven based project, many cached output existed in your “target” folder. When you want to build your project for deployment, you have to make sure clean all the cached output so that you are always get the latest for deployment. To clean your project cached output, issue this command : mvn clean See output… …

Read more

How to build project with Maven

To build a Maven based project, open your console, change to your project folder where pom.xml file is placed, and issue this command : mvn package This will execute the Maven “package” phase. Maven build lifecycle Maven is run by phases, read this default Maven build lifecycle article for more detail. So, when the “package” …

Read more

How to display Maven plugin goals and parameters

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

Maven : generics are not supported in -source 1.3

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

Eclipse : Web Deployment Assembly & Maven dependencies issue

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

How to add M2_REPO classpath variable to Eclipse IDE

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

Download standard.jar (taglib) from Maven

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

Maven dependency libraries not deploy in Eclipse IDE

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 – How to download JavaMail API

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

How to download J2EE API (javaee.jar) from Maven

This below java.net javaee.jar solution is only contains the J2ee APIs, it does not contain any method bodies. It’s fine for compilation, but not for run or deploy your application, because it will caused ” Absent Code attribute in method that is not native or abstract in class” or other method not found errors. Due …

Read more

How to change Maven resources folder location?

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 search the Maven coordinates – pom.xml dependency?

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

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

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

How to add remote repository in Maven

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

Annotations are not supported in -source 1.3 – 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

How to convert Java web project to Maven based project

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

Maven dependency mechanism, how it works

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

How to create a project with Maven template

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

Maven – How to skip unit test

In Maven, you can define a system property -Dmaven.test.skip=true to skip the entire unit test. By default, when building project, Maven will run the entire unit tests automatically. If any unit tests is failed, it will force Maven to abort the building process. In real life, you may STILL need to build your project even …

Read more

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

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