1、新建一個project,並在project下新建一個maven module。
1.1 勾選Create from archetype,選中maven-archetype-webapp,填寫ArtifactId 和 module,finish;
1.2 maven 自動下載需要的jar包,並構建了如下目錄結構:
module name
--src
--main
--resources
--webapp
--WEB-INF
--web.xml
--index.jsp
--pom.xml
1.3 不知為何沒有生成java文件夾,於是手動在main下添加,添加完成後右鍵選擇Make Directory As -- Sources Root
2 添加struts2
2.1 在 pom.xml 中添加 struts2 依賴:
<!-- struts2依賴包 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.14</version>
</dependency>
2.2 在 web.xml 中添加 filter 和 mapping
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.3 在 resources 中添加 struts2.xml 並配置相應的 Action
3 添加應用服務器
3.1 添加 jetty ,在 pom.xml 文件中添加 jetty plugin
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
3.2 或者添加 tomcat ,此處選擇tomcat7
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>9090</port>
<path>/t1</path>
<uriEncoding>UTF-8</uriEncoding>
<finalName>t1</finalName>
<server>tomcat7</server>
</configuration>
</plugin>
4 添加版本控制 git
4.1 單擊IntelliJ idea 工具欄 vcs ,選擇 Import into Version Control -- Create Git Repository
4.2 選中 module 文件夾,OK
4.3 在 module 根目錄添加 .gitignore 文件,設置 git 忽略 .idea 等文件