Created
July 9, 2013 04:59
-
-
Save theotherian/5954823 to your computer and use it in GitHub Desktop.
Maven Archetype how tos Part 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Files for creating a Maven Archtype - part 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<archetype-descriptor name="sample-archetype"> | |
<fileSets> | |
<fileSet filtered="true"> | |
<directory></directory> | |
<includes> | |
<include>pom.xml</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-model</directory> | |
<includes> | |
<include>pom.xml</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-model/src/main/java</directory> | |
<includes> | |
<include>**/*.java</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-model/src/test/java</directory> | |
<includes> | |
<include>**/*.java</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-webapp</directory> | |
<includes> | |
<include>pom.xml</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-webapp/src/main/java</directory> | |
<includes> | |
<include>**/*.java</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-webapp/src/main/webapp/WEB-INF</directory> | |
<includes> | |
<include>web.xml</include> | |
</includes> | |
</fileSet> | |
</fileSets> | |
</archetype-descriptor> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<archetype-descriptor name="sample-archetype"> | |
<fileSets> | |
<fileSet filtered="true"> | |
<directory></directory> | |
<includes> | |
<include>pom.xml</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-model</directory> | |
<includes> | |
<include>pom.xml</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-model/src/main/java</directory> | |
<includes> | |
<include>**/*.java</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>__artifactId__-model/src/test/java</directory> | |
<includes> | |
<include>**/*.java</include> | |
</includes> | |
</fileSet> | |
</fileSets> | |
</archetype-descriptor> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd sample-project | |
$ mvn clean install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p src/main/resources/archetype-resources/__artifactId__-webapp/src/main/java/__packageInPathFormat__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p src/main/resources/archetype-resources/__artifactId__-webapp/src/main/webapp/WEB-INF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependencyManagement> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit-dep</artifactId> | |
<version>4.10</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>servlet-api</artifactId> | |
<version>2.5</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}-model</artifactId> | |
<version>${version}</version> | |
</dependency> | |
</dependencies> | |
</dependencyManagement> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
|____pom.xml | |
|____src | |
| |____main | |
| | |____resources | |
| | | |____archetype-resources | |
| | | | |______artifactId__-model | |
| | | | | |____pom.xml | |
| | | | | |____src | |
| | | | | | |____main | |
| | | | | | | |____java | |
| | | | | | | | |______packageInPathFormat__ | |
| | | | | | | | | |____App.java | |
| | | | | | |____test | |
| | | | | | | |____java | |
| | | | | | | | |______packageInPathFormat__ | |
| | | | | | | | | |____AppTest.java | |
| | | | |______artifactId__-webapp | |
| | | | | |____pom.xml | |
| | | | | |____src | |
| | | | | | |____main | |
| | | | | | | |____java | |
| | | | | | | | |______packageInPathFormat__ | |
| | | | | | | | | |____Servlet.java | |
| | | | | | | |____webapp | |
| | | | | | | | |____WEB-INF | |
| | | | | | | | | |____web.xml | |
| | | | |____pom.xml | |
| | | |____META-INF | |
| | | | |____maven | |
| | | | | |____archetype-metadata.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
|____pom.xml | |
|____src | |
| |____main | |
| | |____resources | |
| | | |____archetype-resources | |
| | | | |____pom.xml | |
| | | | |____src | |
| | | | | |____main | |
| | | | | | |____java | |
| | | | | | | |______packageInPathFormat__ | |
| | | | | | | | |____App.java | |
| | | | | |____test | |
| | | | | | |____java | |
| | | | | | | |______packageInPathFormat__ | |
| | | | | | | | |____AppTest.java | |
| | | |____META-INF | |
| | | | |____maven | |
| | | | | |____archetype-metadata.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mvn clean install | |
$ cd .. | |
$ mvn archetype:generate -DarchetypeCatalog=local | |
[INFO] Scanning for projects... | |
[INFO] | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] Building Maven Stub Project (No POM) 1 | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] | |
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>> | |
[INFO] | |
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<< | |
[INFO] | |
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom --- | |
[INFO] Generating project in Interactive mode | |
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) | |
Choose archetype: | |
1: local -> com.theotherian.archetype:sample-archetype (sample-archetype) | |
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1: 1 | |
Define value for property 'groupId': : com.theotherian | |
Define value for property 'artifactId': : sample-project | |
Define value for property 'version': 1.0-SNAPSHOT: : | |
Define value for property 'package': com.theotherian: : | |
Confirm properties configuration: | |
groupId: com.theotherian | |
artifactId: sample-project | |
version: 1.0-SNAPSHOT | |
package: com.theotherian | |
Y: : | |
[INFO] ---------------------------------------------------------------------------- | |
[INFO] Using following parameters for creating project from Archetype: sample-archetype:1.0-SNAPSHOT | |
[INFO] ---------------------------------------------------------------------------- | |
[INFO] Parameter: groupId, Value: com.theotherian | |
[INFO] Parameter: artifactId, Value: sample-project | |
[INFO] Parameter: version, Value: 1.0-SNAPSHOT | |
[INFO] Parameter: package, Value: com.theotherian | |
[INFO] Parameter: packageInPathFormat, Value: com/theotherian | |
[INFO] Parameter: package, Value: com.theotherian | |
[INFO] Parameter: version, Value: 1.0-SNAPSHOT | |
[INFO] Parameter: groupId, Value: com.theotherian | |
[INFO] Parameter: artifactId, Value: sample-project | |
[WARNING] Don't override file /Users/isimpson/sample-projects/sample-project/pom.xml | |
[INFO] project created from Archetype in dir: /Users/isimpson/sample-projects/sample-project | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] BUILD SUCCESS | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] Total time: 14.574s | |
[INFO] Finished at: Sat May 12 22:14:07 MDT 2012 | |
[INFO] Final Memory: 7M/81M | |
[INFO] ------------------------------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<modules> | |
<module>${artifactId}-model</module> | |
<module>${artifactId}-webapp</module> | |
</modules> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir src/main/resources/archetype-resources/__artifactId__-model | |
$ mv src/main/resources/archetype-resources/src src/main/resources/archetype-resources/__artifactId__-model/ | |
$ mv src/main/resources/archetype-resources/pom.xml src/main/resources/archetype-resources/__artifactId__-model/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}</artifactId> | |
<version>${version}</version> | |
</parent> | |
<artifactId>${artifactId}-model</artifactId> | |
<packaging>jar</packaging> | |
<name>${artifactId}-model</name> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit-dep</artifactId> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}</artifactId> | |
<version>${version}</version> | |
</parent> | |
<artifactId>${artifactId}-model</artifactId> | |
<packaging>jar</packaging> | |
<name>${artifactId}-model</name> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>2.3.2</version> | |
<configuration> | |
<encoding>UTF-8</encoding> | |
<source>1.6</source> | |
<target>1.6</target> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit-dep</artifactId> | |
<version>4.10</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}</artifactId> | |
<version>${version}</version> | |
<packaging>pom</packaging> | |
<name>${artifactId}</name> | |
<modules> | |
<module>${artifactId}-model</module> | |
</modules> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>2.3.2</version> | |
<inherited>true</inherited> | |
<configuration> | |
<encoding>UTF-8</encoding> | |
<source>1.6</source> | |
<target>1.6</target> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencyManagement> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit-dep</artifactId> | |
<version>4.10</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
</dependencyManagement> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}</artifactId> | |
<version>${version}</version> | |
<packaging>pom</packaging> | |
<name>${artifactId}</name> | |
<modules> | |
<module>${artifactId}-model</module> | |
</modules> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}</artifactId> | |
<version>${version}</version> | |
</parent> | |
<artifactId>${artifactId}-webapp</artifactId> | |
<packaging>war</packaging> | |
<name>${artifactId}-webapp</name> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<version>6.1.26</version> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>servlet-api</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>${groupId}</groupId> | |
<artifactId>${artifactId}-model</artifactId> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd sample-project-webapp | |
$ mvn jetty:run-war |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ${package}; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
public class Servlet extends HttpServlet { | |
@Override | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
response.setStatus(200); | |
PrintWriter writer = response.getWriter(); | |
writer.write(App.message()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | |
<servlet> | |
<display-name>${artifactId}</display-name> | |
<servlet-name>${artifactId}</servlet-name> | |
<servlet-class>${package}.Servlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>${artifactId}</servlet-name> | |
<url-pattern>/${artifactId}</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment