初設 AJSP 專案
$ mvn archetype:create -DgroupId=kvm.jsp -DartifactId=AJSP
-DarchetypeArtifactId=maven-archetype-webapp
Counter.java 資料物件設計
1. 建立 foo 套件目錄
$ mkdir -p AJSP/src/main/java/foo
2. 撰寫 Counter.java 程式
$ nano AJSP/src/main/java/foo/Counter.java
package foo;
public class Counter {
private static int count;
public static synchronized int getCount() {
count++;
return count;
}
}
撰寫 MyJSP01.jsp
$ nano AJSP/src/main/webapp/MyJSP01.jsp
<html>
<body>
The Page count is :
<%
out.println(foo.Counter.getCount());
%>
</body>
</html>
製作 AJSP 專案檔 (AJSP.war)
$ cd AJSP
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AJSP Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ AJSP ---
[WARNING] Using platform encoding (ANSI_X3.4-1968 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ AJSP ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ AJSP ---
[WARNING] Using platform encoding (ANSI_X3.4-1968 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /mnt/hda1/AJSP/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ AJSP ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ AJSP ---
[INFO] No tests to run.
[INFO] Surefire report directory: /mnt/hda1/AJSP/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ AJSP ---
[INFO] Packaging webapp
[INFO] Assembling webapp [AJSP] in [/mnt/hda1/AJSP/target/AJSP]
[INFO] Processing war project
[INFO] Copying webapp resources [/mnt/hda1/AJSP/src/main/webapp]
[INFO] Webapp assembled in [78 msecs]
[INFO] Building war: /mnt/hda1/AJSP/target/AJSP.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.804s
[INFO] Finished at: Sun Aug 07 10:00:12 UTC 2011
[INFO] Final Memory: 5M/13M
[INFO] ------------------------------------------------------------------------
檢視 AJSP 專案檔製作後, AJSP 的目錄結構
$ tree .
.
|-- pom.xml
|-- src
| `-- main
| |-- java
| | `-- foo
| | `-- Counter.java
| |-- resources
| `-- webapp
| |-- MyJSP01.jsp
| |-- WEB-INF
| | `-- web.xml
| `-- index.jsp
`-- target
|-- AJSP
| |-- META-INF
| |-- MyJSP01.jsp
| |-- WEB-INF
| | |-- classes
| | | `-- foo
| | | `-- Counter.class
| | `-- web.xml
| `-- index.jsp
|-- AJSP.war
|-- classes
| `-- foo
| `-- Counter.class
|-- maven-archiver
| `-- pom.properties
`-- surefire
17 directories, 12 files
佈署 AJSP 專案至 Tomcat
$ cp target/AJSP.war /mnt/hda1/apache-tomcat-7.0.19/webapps/
啟動 Tomcat
$ /mnt/hda1/apache-tomcat-7.0.19/bin/startup.sh &
[1] 1321
Using CATALINA_BASE: /mnt/hda1/apache-tomcat-7.0.19
Using CATALINA_HOME: /mnt/hda1/apache-tomcat-7.0.19
Using CATALINA_TMPDIR: /mnt/hda1/apache-tomcat-7.0.19/temp
Using JRE_HOME: /mnt/hda1/jdk1.7.0
Using CLASSPATH: /mnt/hda1/apache-tomcat-7.0.19/bin/bootstrap.jar:/mnt/hda1/apache-tomcat-7.0.19/bin/tomcat-juli.jar
執行 MyJSP01.jsp
$ curl http://localhost:8080/AJSP/MyJSP01.jsp
<html>
<body>
The Page count is :
1
</body>
</html>
2011年8月6日 星期六
訂閱:
張貼留言 (Atom)
No Response to "Apache Maven 專案管理平台 - WAR 專案加入 JSP"
張貼留言