mvn war:exploded
网站项目通常不必打包war,发布时直接用WinSCP同步WebContent目录即可,命令mvn war:exploded可以构建完整的可直接被tomcat加载运行的WebContent目录,同时调试java和jsp都很方便。
一种方式是直接编译输出class到WebContent/WEB-INF/classes目录(这时WEB-INF/lib会有jar包),然后用tomcat直接加载WebContent目录
<build>
<resources><resource><directory>src/main/resources</directory></resource></resources>
<outputDirectory>WebContent/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<webappDirectory>WebContent</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
另一种方式是编译输出到另外的目录(class+jsp+jar等),这时需要将WebContent也加入Source并输出到目标目录以便调试jsp(使用WebContentLink链接),同时WebContent/WEB-INF/classes链接到真正目标目录${target}/WebContent/WEB-INF/classes
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.test.skip>true</maven.test.skip>
<targets.home>E:\work2\Servers\web</targets.home>
</properties>
<build>
<directory>${targets.home}/${project.artifactId}/target</directory>
<outputDirectory>${targets.home}/${project.artifactId}/WebContent/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<webappDirectory>${targets.home}/${project.artifactId}/WebContent</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
调试运行或发布WebContent目录即可
<Context docBase="E:\work2\Servers\web\MyWeb\WebContent" path="/MyWeb"/>