不同环境环境下的爬虫协议是不同的,尤其测试、开发的数据,不允许被搜索引擎爬虫。所有有了这个需求,最终解决方案:
0. 基于maven的分环境打包
1. 文件放于分环境打包的不同环境目录下
2. 使用maven-resources-plugin插件实现将robots.txt文件复制至war的根目录下
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/${env}/</directory>
<includes>
<include>robots.txt</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>