Posts Tagged ‘archetype

25
Feb
11

MySQL Test Connection using Spring MVC

This page will describe how to create a spring MVC application to test a connection to MySQL database. The user will provide the connection URL and username/password. The system will make a simple connection to the database and return the results to the screen.

Note: This page was originally written in November 15 2009.

Requirements

  • Access to a MySQL Server
  • Maven 2
  • Eclipse
  • Spring 2.5
  • Java 1.5 or above

Start a new Project

Start a new project by creating it from an archetype.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp
Choose option:

Answer the questions like this:

Define value for groupId: : test
Define value for artifactId: : spring-mysql-test
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  test: :
Confirm properties configuration:
groupId: test
artifactId: spring-mysql-test
version: 1.0-SNAPSHOT
package: test
 Y: :

cd spring-mysql-test
modify pom.xml and insert the following dependencies

	<dependencies>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.9</version>
		</dependency>
		<dependency>
		  <groupId>org.springframework</groupId>
		  <artifactId>spring</artifactId>
		  <version>2.5.6</version>
		</dependency>
		<dependency>
		  <groupId>org.springframework</groupId>
		  <artifactId>spring-webmvc</artifactId>
		  <version>2.5.6</version>
		</dependency>
	<dependency>
		<groupId>org.apache.geronimo.specs</groupId>
		<artifactId>geronimo-servlet_2.5_spec</artifactId>
		<version>1.2</version>
		<type>jar</type>
		<scope>provided</scope>
	</dependency>
	</dependencies>

insert the following into

src/main/webapp/WEB-INF/web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>/app/helloWorld</welcome-file>
</welcome-file-list>

</web-app>

Insert the following into

src/main/webapp/WEB-INF/spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>  
  
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">

	<context:component-scan base-package="test" />

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>

</beans>

Java Code

Before writing the Java files please create the following directory.

mkdir -p src/main/java/test

Create a java class that looks like this…
src/main/java/test/HelloWorldController.java

package test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.stereotype.Controller;

@Controller("/helloWorld")
public class HelloWorldController extends AbstractController {
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		ModelAndView mav = null;
		// control logic goes here
		mav = new ModelAndView("helloWorld");
		return mav;
	}
}

mkdir -p src/main/webapp/WEB-INF/jsp

src/main/webapp/WEB-INF/jsp/helloWorld.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title>HelloWorld test page</title>
		<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
		<meta http-equiv="Content-Language" content="en-us" />
	</head>
	
	<body>
		Hello World page!
	</body>
</html>

Run the Project

In order to run the project we need to put a couple of more things into pom.xml file.

1. The jetty plugin will allow Maven to run the project in the jetty servlet container. In the plug-in section of the pom.xml file put in the following…
2. By default Maven uses an old version of the JDK to compile. We need to set it to use a higher version. (supports annotations). If you don’t have 1.6 then change the source and target elements below to 1.5 at least.

pom.xml inside the build tag

  <build>
    <finalName>spring-mysql-test</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.0.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>7.0.0.v20091005</version>
				<configuration>
					<scanIntervalSeconds>1</scanIntervalSeconds>
				</configuration>
			</plugin>
		</plugins>
  </build>

To run the web application type:
type

mvn jetty:run

Navigate your browser to http://localhost:8080/app/helloWorld to test if everything is okay up to this point. If something is not working please review the steps seen above and make sure you at least see hello world printed on the screen.

We will create a Controller that draws a input form that the user can use to specify database url, username, password.

src/main/java/test/DBParam.java

package test;

public class DBParam {
    public String url;
    public String username;
    public String password;
    
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

}

The controller will take this form submission and make a connection to the database with the results printed to the screen.

src/main/java/test/TestDBConnectionController.java

package test;

import java.sql.Connection;
import java.sql.DriverManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

@Controller("/dbParameters")
public class TestDBConnectionController extends SimpleFormController {

	public TestDBConnectionController() {
		setFormView("dbParameters");
		setCommandClass(DBParam.class);
		setSuccessView("success");
		setCommandName("dbParam");
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		System.out.println("form submitted");

		DBParam dbParam = (DBParam)command;
		String url = dbParam.getUrl();
		String username = dbParam.getUsername();
		String password = dbParam.getPassword();

		// make a connection
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		Connection conn = DriverManager.getConnection(url, username, password);
		System.out.println("got a connection: " + conn);

		return super.processFormSubmission(request, response, command, errors);
	}
}

We have enabled component scanning in our spring-servlet.xml file so we don’t have to register this controller in the xml file.

src/main/webapp/WEB-INF/jsp/dbParameters.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>DB Parameters</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

</head>
<body>
	<form method="post">
		<label>JDBC connect string: </label><input type="text" name="url" value="jdbc:mysql://hostname:3306/dbname" size="55"/><br/>
		<label>password: </label><input type="text" name="username"/><br/>
		<label>username: </label><input type="password" name="password"/><br/>
		<input type="submit" value="submit"/><br/>
	</form>
</body>
</html>

src/main/webapp/WEB-INF/jsp/success.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>DB Parameters</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

</head>
<body>
	success
</body>
</html>

Run the project

You may run the project under jetty

mvn jetty:run

navigate your browser to:

http://localhost:8080/app/dbParameters

Replace the URL with the url to your mysql database.

That’s it for now!!!

23
Nov
09

Hello Enterprise Application

This page will show you how to create an Jave Enterprise application using Maven’s multi-module and archetype capabilities.

Requirements

  • Maven
  • Eclipse IDE
  • Java 5 or above
  • Access to the Command Prompt

Hello Enterprise

In the example we will name the application HelloEnterprise. This will be the parent project. The project will have 3 sub-projects listed below.

  1. HelloModel – contains the business logic
  2. HelloWeb – contains the Web application flow control logic
  3. HelloEar – small sub-project used simply to create the ear

Create the Parent Project

The first step we will do is to create the parent project. This project will contain the others. Name the project something that is generic to the problem at hand.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart

Define value for groupId: : test
Define value for artifactId: : hello-enterprise
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  test: :
Confirm properties configuration:
groupId: test
artifactId: hello-enterprise
version: 1.0-SNAPSHOT
package: test
 Y: :

cd hello-enterprise
Edit the pom.xml and change the packaging to say pom instead of jar.

Create the Model project

For this step we will create a very simple model project that simply contains a single Model class. Though this is a very simple project it does show you how you can combine sub-modules into one ear file in the end.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart

This time answer the artifact id should be “hello-enterprise-model”.

Go ahead and create the model class

cd hello-enterprise-model

mvn eclipse:eclipse

Import the project into eclipse and create the following class and interface

Bean

package test;

import java.math.BigDecimal;

public class Product {
	private Integer id;
	private String name;
	private BigDecimal price;

	public Product(Integer id, String name, BigDecimal price) {
		this.id = id;
		this.name = name;
		this.price = price;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
}

Interface

package test;

import java.util.List;

public interface ProductDataManager {

	public abstract List<Product> getAllProducts();

}

Class

package test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class ProductDataManagerImpl implements ProductDataManager {
	/* (non-Javadoc)
	 * @see test.ProductDataManager#getAllProducts()
	 */
	public List<Product> getAllProducts() {
		List<Product> list = new ArrayList<Product>();

		list.add(createProduct(1, "test1", BigDecimal.valueOf(12)));
		list.add(createProduct(2, "test2", BigDecimal.valueOf(13)));
		list.add(createProduct(3, "test3", BigDecimal.valueOf(14)));

		return list;
	}
	private Product createProduct(Integer id, String name, BigDecimal price) {
		Product product = new Product(id, name, price);
		return product;
	}
}

cd ..

Create the web project

To create the web project we will use an existing archetype that was created my me. It is an archetype of a very simple spring MVC application that prints some static text on the screen.

mvn archetype:generate -DarchetypeGroupId=com.vermatech \
-DarchetypeArtifactId=springmvc-archetype -DarchetypeVersion=1.0-SNAPSHOT \
-DarchetypeRepository=http://www.vermatech.com/m2repo

Answer the questions like this:

Define value for groupId: : test
Define value for artifactId: : hello-enterprise-web
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  test: :
Confirm properties configuration:
groupId: test
artifactId: hello-enterprise-web
version: 1.0-SNAPSHOT
package: test
 Y: :

You may test the project you just created from an archetype by typing mvn jetty:run from the hello-enterprise-web folder. Point your browser to: http://localhost:8080/ and verify everything is ok.

When you are done return to the command prompt and cd to the hello-enterprise directory again.

Create the Ear Project

Finally we will create an EAR project that will allow us to create an EAR file.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart

Edit pom.xml and make sure it looks like the following.

hello-enterprise/hello-enterprise-ear/pom.xml

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>hello-enterprise</artifactId>
    <groupId>test</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>test</groupId>
  <artifactId>hello-enterprise-ear</artifactId>
  <packaging>ear</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>hello-enterprise-ear</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>test</groupId>
      <artifactId>hello-enterprise-model</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>test</groupId>
      <artifactId>hello-enterprise-web</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>war</type>
    </dependency>

  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.3.2</version>
        <!-- configuring the ear plugin -->
        <configuration>
          <modules>
            <webModule>
              <groupId>test</groupId>
              <artifactId>hello-enterprise-web</artifactId>
            </webModule>
          </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Save and exit. Return to the hello-enterprise (parent) directory and run the following command:

Start the build process

mvn package

You will see a bunch of stuff happen and at the end you will see the following results.

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] hello-enterprise ...................................... SUCCESS [1.194s]
[INFO] hello-enterprise-model ................................ SUCCESS [0.938s]
[INFO] springmvc-quickstart Maven Webapp ..................... SUCCESS [1.078s]
[INFO] hello-enterprise-ear .................................. SUCCESS [0.647s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

At this time you can open the ear project’s target folder and you will see the newly created ear.

Deploy The Ear file

Deploy the Ear to your Application server and do an application checkout.

That’s All

[INFO] ————————————————————————
[INFO] Reactor Summary:
[INFO] ————————————————————————
[INFO] hello-enterprise ……………………………….. SUCCESS [1.194s]
[INFO] hello-enterprise-model ………………………….. SUCCESS [0.938s]
[INFO] springmvc-quickstart Maven Webapp ………………… SUCCESS [1.078s]
[INFO] hello-enterprise-ear ……………………………. SUCCESS [0.647s]
[INFO] ————————————————————————
[INFO] ————————————————————————
[INFO] BUILD SUCCESSFUL
[INFO] ————————————————————————

22
Nov
09

Spring MVC application using Archetypes

The following page describes the process of creating a simple spring MVC application using an archetype. The archetype was created my me for testing purposes. All it does is print a simple message to the browser when you navigate to the application.

Requirements

Maven

Access to the command prompt

The Maven page above talks about eclipse you don’t need eclipse to install and run the simple springMVC application described here.

Creating the Project

Execute the following archetype to create the spring MVC application

mvn archetype:generate -DarchetypeGroupId=com.vermatech \
-DarchetypeArtifactId=springmvc-archetype -DarchetypeVersion=1.0-SNAPSHOT \
-DarchetypeRepository=http://www.vermatech.com/m2repo

Answer some simple questions:

Define value for groupId: : com.test2
Define value for artifactId: : vtSpringTest
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  com.test2: :
Confirm properties configuration:
groupId: com.test2
artifactId: vtSpringTest
version: 1.0-SNAPSHOT
package: com.test2
 Y: :

Running the Application in Jetty

Execute the following in the project’s folder.

mvn jetty:run

Navigate to the following url http://localhost:8080/ and you should see a Welcome page come up.

Advanced Jetty Settings

The following allows jetty to serve from a different context root. It also allows the application to be reloaded 2 seconds after a change is detected to the classes or the web.xml file.

	<plugin>
		<groupId>org.mortbay.jetty</groupId>
		<artifactId>jetty-maven-plugin</artifactId>
				<version>7.0.0.v20091005</version>
		<configuration>
			<scanIntervalSeconds>2</scanIntervalSeconds>
			<webAppConfig>
				<contextPath>/biggerstrongerbetterfaster</contextPath>			
			</webAppConfig>
		</configuration>
	</plugin> 

Thats All!

15
Nov
09

Creating a new Maven Archetype and Publishing it to Nexus

This page will describe the process to create and upload a new archetype to the repository.

We will be creating an archetype of a basic spring MVC application that is pre-configured to make a test connection to a MySQL database. We will run this application using the built in servlet engine in Maven called jetty.

Before starting please review the following article to learn how to publish artifacts to remote repositories.

Requirements

Create a Archetype Template

We start by creating an archetype from well…. an archetype…

Execute the following command

mvn archetype:create -DgroupId=test -DartifactId=test-archetype -DarchetypeArtifactId=maven-archetype-archetype

cd /test-archetype

Code Your Application

In this section we will take some time to code the project that we will install into this archetype. Since creating a Spring MVC application is beyond the scope of this page please navigate to the following page to see how this application was coded. We will move this application to this archetype so that it can be used as a starting point for new projects.

MySQL Test Connection using Spring MVC

Import files into the new archetype

At this time you can copy the files from the project you created using the above link into the src/main/resources/archetype-resources/

Before we can proceed we need to make some small changes to the project we just created and imported into this archetype.

These changes are necessary because when developers create project based on archetypes they are asked a few questions.

  • group id
  • artifact id
  • version

The group id is important typically its (com.yourcompanyname). Since developers can provide anything in this field you need to modify your template code to take this parameter and place your code into the right java packages.

Modify the project’s pom.xml

Before we can proceed we need to modify the template project’s pom.xml file. Replace the groupId artifactId and version tag’s with the following

  <groupId>${groupId}</groupId>
  <artifactId>${artifactId}</artifactId>
  <version>${version}</version>

The above step is necessary since the developers that are using your archetype to create their own project can use any group artifact and version. When the project generates maven needs to create a pom.xml file for the project with the values that were specified by the developer.

Modify the archetype descriptor

The archetype descriptor contains a list of files that are part of the archetype we are creating. It is located in the following directory.

test-archetype/src/main/resources/META-INF/maven/archetype.xml

<archetype>
  <id>test-archetype</id>
  <sources>
    <source>src/main/java/test/DBParam.java</source>
    <source>src/main/java/test/HelloWorldController.java</source>
    <source>src/main/java/test/TestDBConnectionController.java</source>
  </sources>
  <resources>
    <resource>src/main/webapp/WEB-INF/jsp/dbParameters.jsp</resource>
    <resource>src/main/webapp/WEB-INF/jsp/helloWorld.jsp</resource>
    <resource>src/main/webapp/WEB-INF/jsp/success.jsp</resource>
    <resource>src/main/webapp/WEB-INF/spring-servlet.xml</resource>
    <resource>src/main/webapp/WEB-INF/web.xml</resource>
    <resource>src/main/webapp/index.jsp</resource>
  </resources>
</archetype>

Modify the source files

During the creation of a project maven asks the user for the groupId. Maven uses this to place the source files into packages that represent the user’s groupId. For this reason we need to modify each of the source packages and change them to look like this…

package ${package}.test;

So go ahead and modify the three java source files and spring-servlet.xml. replace the package statement with what you see above.

  • src/main/java/test/DBParam.java
  • src/main/java/test/HelloWorldController.java
  • src/main/java/test/TestDBConnectionController.java
  • src/main/webapp/WEB-INF/spring-servlet.xml

Relocate Source If Necessary

Also you may need to relocate the .java files so they represent the package statement. This means if you replaced the following with a ${package} statement then everything under that must be moved to the highlevel folder.

com.mycompany.mygroup.program -> ${package}.program

In the above example the program package and everything under it needs to be moved to the top level (/src/main/java) folder.

The xml file needs to be modified because we need to tell spring to scan a different package for controller beans.

	<context:component-scan base-package="${package}.test"/>

Installing the archetype into Nexus

Make sure the nexus repository is up and running.

Before we publish the archetype we need to define the location of the Nexus repository.

We do this in the archetype’s pom.xml file

After adding this section your pom.xml file should look like this.

<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>test</groupId>
  <artifactId>test-archetype</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Archetype - test-archetype</name>
  <url>http://maven.apache.org</url>

<distributionManagement>
	<repository>
		<id>releases</id>
		<url>http://localhost:8081/nexus/content/repositories/releases</url>
	</repository>

	<snapshotRepository>
		<id>snapshots</id>
		<name>Internal Snapshots</name>
		<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
	</snapshotRepository>
</distributionManagement>
</project>

mvn deploy

Open up the Nexus repository and verify that the archetype has been added. If it has not please review the instructions above before continuing.

Running the Archetype

In this section we will generate a project from an archetype we just created above.

open up the command line and navigate to a clean working directory.

mvn archetype:create \
  -DarchetypeGroupId=test \
  -DarchetypeArtifactId=test-archetype \
  -DarchetypeVersion=1.0-SNAPSHOT \
  -DgroupId=yourgroup \
  -DartifactId=your-project

You can also use the new format to generate a project form an archetype:

mvn archetype:generate \
  -DarchetypeGroupId=test \
  -DarchetypeArtifactId=test-archetype \
  -DarchetypeVersion=1.0-SNAPSHOT

Running your newly generated project

cd your-project
mvn jetty:run

At this point you can navigate to all the urls listed below:

http://localhost:8080/

http://localhost:8080/app/helloWorld

http://localhost:8080/app/dbParameters

Publishing your Archetype to a Website

Good News! You don't need a Nexus server. Maven artifacts can be published to plain old web sites.

To test this I have uploaded the test-archetype to the following location and used the following command to generate a project based on the archetype.

mvn archetype:generate \
  -DarchetypeGroupId=test \
  -DarchetypeArtifactId=test-archetype \
  -DarchetypeVersion=1.0-SNAPSHOT \
  -DarchetypeRepository=http://your static site hostname/directory of your repository

Maven makes a Http connection to the above archetypeRepository and gets all the data necessary to create the project.

Summary

As you can see creating an archetype is not much difficult. You can use this technique to create templates of small projects you find yourself creating often. Archetypes can be posted not only to Nexus repositories but static html sites as well.

That's all for now!!!

Hope this helped. If so please rate this page and/or leave me a comment.




Follow

Get every new post delivered to your Inbox.

Join 34 other followers