Last active
October 11, 2020 18:49
-
-
Save theotherian/5954779 to your computer and use it in GitHub Desktop.
Maven Archetype how to samples for http://www.theotherian.com/2012/05/maven-archetypes-part-2-how-do-i-create.html
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 Maven archetypes - part 2 |
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}; | |
public class App { | |
public static void main(String args[]) { | |
System.out.println(message()); | |
} | |
public static String message() { | |
return "Hello world!"; | |
} | |
} |
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 static org.junit.Assert.*; | |
import org.junit.Test; | |
public class AppTest { | |
@Test | |
public void message() throws Exception { | |
assertEquals("Hello world!", 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
<archetype-descriptor name="sample-archetype"> | |
<fileSets> | |
<fileSet filtered="true"> | |
<directory></directory> | |
<includes> | |
<include>pom.xml</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>src/main/java</directory> | |
<includes> | |
<include>**/*.java</include> | |
</includes> | |
</fileSet> | |
<fileSet filtered="true"> | |
<directory>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
$ mvn clean install | |
$ cd .. |
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-jar | |
$ mvn clean package | |
[INFO] Scanning for projects... | |
[INFO] | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] Building sample-jar 1.0-SNAPSHOT | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] | |
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ sample-jar --- | |
[INFO] | |
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ sample-jar --- | |
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! | |
[INFO] skip non existing resourceDirectory /Users/isimpson/sample-projects/sample-jar/src/main/resources | |
[INFO] | |
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ sample-jar --- | |
[INFO] Compiling 1 source file to /Users/isimpson/sample-projects/sample-jar/target/classes | |
[INFO] | |
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ sample-jar --- | |
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! | |
[INFO] skip non existing resourceDirectory /Users/isimpson/sample-projects/sample-jar/src/test/resources | |
[INFO] | |
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ sample-jar --- | |
[INFO] Compiling 1 source file to /Users/isimpson/sample-projects/sample-jar/target/test-classes | |
[INFO] | |
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ sample-jar --- | |
[INFO] Surefire report directory: /Users/isimpson/sample-projects/sample-jar/target/surefire-reports | |
------------------------------------------------------- | |
T E S T S | |
------------------------------------------------------- | |
Running com.theotherian.AppTest | |
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 sec | |
Results : | |
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 | |
[INFO] | |
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ sample-jar --- | |
[INFO] Building jar: /Users/isimpson/sample-projects/sample-jar/target/sample-jar-1.0-SNAPSHOT.jar | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] BUILD SUCCESS | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] Total time: 1.740s | |
[INFO] Finished at: Sat May 12 12:05:52 MDT 2012 | |
[INFO] Final Memory: 9M/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
$ mkdir -p src/main/resources/archetype-resources/src/main/java/__packageInPathFormat__ | |
$ mkdir -p src/main/resources/archetype-resources/src/test/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
$ 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 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-jar | |
Define value for property 'version': 1.0-SNAPSHOT: : | |
Define value for property 'package': com.theotherian: : | |
Confirm properties configuration: | |
groupId: com.theotherian | |
artifactId: sample-jar | |
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-jar | |
[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-jar | |
[WARNING] Don't override file /Users/isimpson/sample-projects/sample-jar/pom.xml | |
[INFO] project created from Archetype in dir: /Users/isimpson/samples-projects/sample-jar | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] BUILD SUCCESS | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] Total time: 1:29.976s | |
[INFO] Finished at: Sat May 12 12:00:34 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
<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>jar</packaging> | |
<name>${artifactId}</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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment