1

我使用虚拟目录来服务用户上传的静态资源。所以我在重新部署应用程序时不需要备份这些文件。

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> 
  <Context path="/upload" docBase="/Users/junyu/Web/upload/"/> 
</Host>

我把这些代码写到server/server.xml中,可以被gretty buildProduct任务检测到。这里是输出目录: directory

运行输出: 输出

上传上下文成功启动,但我无法访问 docBase 中的图片。404 错误。

放弃使用 server.xml 配置上下文的方法。只需在 output/hello-web/server.json 中配置如下:

"webApps": [
    { "contextPath": "/hello-web", "resourceBase": "webapps/hello-web.war" },
    { "contextPath": "/upload", "resourceBase": "/Users/junyu/Web/upload/" } 
]

上传上下文将起作用,并且可以访问 docBase 中的图片。

问题是每次构建都会新生成 server.json,我必须再次更改 server.json。有没有办法一劳永逸地配置。

并且,“Web-app extra resource bases”只是将资源复制到项目中,原始资源文件更改后不会更改。

4

0 回答 0