- Create webapp project:
$ mvn \ archetype:generate \ -DarchetypeArtifactId=maven-archetype-webapp \ -DinteractiveMode=false \ -DgroupId=com.myMaven.app \ -DartifactId=HelloJavaWeb [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 Batch mode (Downloading packages...) [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.myMaven.app [INFO] Parameter: packageName, Value: com.myMaven.app [INFO] Parameter: package, Value: com.myMaven.app [INFO] Parameter: artifactId, Value: HelloJavaWeb [INFO] Parameter: basedir, Value: /home/linst/ws/study/maven [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/linst/ws/study/maven/HelloJavaWeb [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:31.939s [INFO] Finished at: Mon Sep 29 15:28:36 CST 2014 [INFO] Final Memory: 11M/302M [INFO] ------------------------------------------------------------------------
. └── HelloJavaWeb ├── pom.xml └── src └── main ├── resources └── webapp ├── index.jsp └── WEB-INF └── web.xml 6 directories, 3 files
- pom.xml:
4.0.0 com.myMaven.app HelloJavaWeb war 1.0-SNAPSHOT HelloJavaWeb Maven Webapp http://maven.apache.org junit junit 3.8.1 test HelloJavaWeb - Compile and packaging:
$ cd HelloJavaWeb/ $ mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building HelloJavaWeb Maven Webapp 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ HelloJavaWeb --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ HelloJavaWeb --- [INFO] No sources to compile [INFO] [INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ HelloJavaWeb --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/linst/ws/study/maven/HelloJavaWeb/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ HelloJavaWeb --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ HelloJavaWeb --- (Downloading packages...) [INFO] No tests to run. [INFO] Surefire report directory: /home/linst/ws/study/maven/HelloJavaWeb/target/surefire-reports (Downloading packages...) ------------------------------------------------------- T E S T S ------------------------------------------------------- Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.1.1:war (default-war) @ HelloJavaWeb --- [INFO] Packaging webapp [INFO] Assembling webapp [HelloJavaWeb] in [/home/linst/ws/study/maven/HelloJavaWeb/target/HelloJavaWeb] [INFO] Processing war project [INFO] Copying webapp resources [/home/linst/ws/study/maven/HelloJavaWeb/src/main/webapp] [INFO] Webapp assembled in [15 msecs] [INFO] Building war: /home/linst/ws/study/maven/HelloJavaWeb/target/HelloJavaWeb.war [INFO] WEB-INF/web.xml already added, skipping [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 10.573s [INFO] Finished at: Mon Sep 29 15:36:19 CST 2014 [INFO] Final Memory: 7M/239M [INFO] ------------------------------------------------------------------------
. ├── pom.xml ├── src │ └── main │ ├── resources │ └── webapp │ ├── index.jsp │ └── WEB-INF │ └── web.xml └── target ├── classes ├── HelloJavaWeb │ ├── index.jsp │ ├── META-INF │ └── WEB-INF │ ├── classes │ └── web.xml ├── HelloJavaWeb.war ├── maven-archiver │ └── pom.properties └── surefire 13 directories, 7 files
- You can see the generated "HelloJavaWeb.war" which can be deploy to Tomcat web server.
- Adding jar files, ex: modify pom.xml to add mysql dependency:
4.0.0 com.myMaven.app HelloJavaWeb war 1.0-SNAPSHOT HelloJavaWeb Maven Webapp http://maven.apache.org junit junit 3.8.1 test mysql mysql-connector-java 5.1.24 HelloJavaWeb - Compile and packaging:
$ mvn package
. ├── pom.xml ├── src │ └── main │ ├── resources │ └── webapp │ ├── index.jsp │ └── WEB-INF │ └── web.xml └── target ├── classes ├── HelloJavaWeb │ ├── index.jsp │ ├── META-INF │ └── WEB-INF │ ├── classes │ ├── lib │ │ └── mysql-connector-java-5.1.24.jar │ └── web.xml ├── HelloJavaWeb.war ├── maven-archiver │ └── pom.properties └── surefire 14 directories, 8 files
- You can see the generated "mysql-connector-java-5.1.24.jar" and it will also be packaged in "HelloJavaWeb.war".
- References:
http://mkn939.blogspot.tw/2013/03/maven-hellomaven-maven-step-by-step.html [Chinese]
Monday, September 29, 2014
Apache Maven first project for "archetypeArtifactId=maven-archetype-webapp"
Labels:
Maven
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment