Spring + JDBC example

In this tutorial, we will extend last Maven + Spring hello world example by adding JDBC support, to use Spring + JDBC to insert a record into a customer table. 1. Customer table In this example, we are using MySQL database. CREATE TABLE `customer` ( `CUST_ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `NAME` varchar(100) NOT NULL, …

Read more

Maven + Spring hello world example

This quick guide example uses Maven to generate a simple Java project structure, and demonstrates how to retrieve Spring bean and prints a “hello world” string. Technologies used in this article : Spring 2.5.6 Maven 3.0.3 Eclipse 3.6 JDK 1.6.0.13 Spring 3 example For Spring 3, refer to this Maven + Spring 3 hello world …

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

Maven 2 + Hibernate 3.2 + MySQL Example (Annotation)

Note This article is outdated, and some information is no longer valid in latest Hibernate development. You should refer to this latest – Maven 3 + Hibernate 3.6.3 + Oracle 11g Example (Annotation) tutorial. This tutorial will modify the previous Maven 2 + Hibernate 3.2 + MySQL Example (XML mapping), and replace the Hibernate XML …

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

How to create an Ant build file from Maven (pom.xml)?

In some cases, you may need to generate Ant build file (build.xml) for your project integration purpose. For example, the klockwork code analysis tool is required Ant file to perform the static code analysis processes for java project. Maven Ant plugin Maven comes with a handy Ant plugin to generate Ant build file from Maven …

Read more

How to download from Maven remote repository?

According to Apache Maven : Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer). By default, Maven will download from the central repository. In Maven, when you’re declared library does not exist …

Read more

Where is Maven Central Repository?

By default, Maven will get project dependencies from Maven Local Repository, if it is not found, Maven will get it from the Maven Central Repository Maven Central Repository URL – https://repo.maven.apache.org/maven2 Maven Central Repository Search – https://search.maven.org/ This is how the Maven central repository search website looks like : History This is how the Maven …

Read more

Where is Maven local repository?

By default, Maven local repository is defaulted to ${user.home}/.m2/repository folder : Unix/Mac OS X – ~/.m2/repository Windows – C:\Users\{your-username}\.m2\repository When we compile a Maven project, Maven will download all the project’s dependency and plugin jars into the Maven local repository, save time for next compilation. 1. Find Maven Local Repository 1.1 If the default .m2 …

Read more