默认情况下,web-app 下的文件在像 tomcat 这样的应用程序容器中作为静态资源提供。因此,如果我将 helloworld.html 之类的文件保存在其中,我可以在浏览器中查看它
http://localhost:8080/myapp/helloworld.html
是否可以配置除 web-app 以外的其他文件夹来提供静态内容。我宁愿从war文件本身中执行此操作,而不必以tomcat范围的方式对其进行配置。
有什么建议么?
Maven's war plugin is a good fit here. This offers several configuration options when building the war so it'll be independent of your web server.
And an example where a different directory can be hosted as you suggest
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>resource2</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Here's an another example they give where a different webapp folder can be used.
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
...
</project>