總結
我是個現實主義者,我喜歡目前自己所從事的一切,並對此始終深信不疑。 – 巴菲特。
從做中學累積經驗真的很快,但是沒記下來,就等於沒有。這段期間歷經了幾個問題:
- 編碼議題 (properties)
- 如何建立本地函示庫 (repository)
- 特定函式庫只想要支援 compile 階段,但是 package、deploy 不包含。(scope)
- FCKeditor 不想要用它依賴的 slf4j-api 版本。(exclusions)
- 依照佈署環境產生不同的設定檔。(profiles)
有些問題之前已經在 Migrate Tomcat Webapp to Maven QA 分享過了,所以直接看成品囉。
成品
google plus comments
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
| <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>wild.wind</groupId>
<artifactId>WildTest</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>WildTest Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<!-- 建立 Local 函示庫 -->
<repository>
<id>ProjectRepo</id>
<name>ProjectRepo</name>
<url>file:///${project.basedir}/libs</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- servlet, tomcat 本身應該要有,所以指定 provided -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- jsp, tomcat 本身應該要有,所以指定 provided -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- MySQL JDBC, 模擬佈署環境 tomcat 自己放,所以指定 provided -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.2.18</version>
<scope>provided</scope>
</dependency>
<!-- Oracle JDBC, 模擬佈署環境 tomcat 自己放,所以指定 provided -->
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<!-- Struts -->
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<version>1.2.0</version>
</dependency>
<!-- FCKeditor, 改用比較新的 slf4j-api -->
<dependency>
<groupId>net.fckeditor</groupId>
<artifactId>java-core</artifactId>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- slf -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.5.8</version>
</dependency>
<!-- 去 Local 函示庫找 Jar 檔 -->
<dependency>
<groupId>wild</groupId>
<artifactId>wind</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>wild</groupId>
<artifactId>wild</artifactId>
<version>1.0</version>
<classifier>encode</classifier>
</dependency>
<dependency>
<groupId>wild</groupId>
<artifactId>wild</artifactId>
<version>1.0</version>
<classifier>decode</classifier>
</dependency>
</dependencies>
<profiles>
<!-- 本機開發設定檔 -->
<profile>
<id>dev_local</id>
<activation> <!-- 預設使用此設定檔 -->
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webconf/dev_local</directory>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- 線上設定檔 -->
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webconf/prod</directory>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<finalName>WildTest</finalName>
</build>
</project>
|