创建仅包含图像的战争
我正在尝试创建一场将在 EAR 中部署的战争,并且应该仅包含图像。
我的战争源组织如下:
+---src
| +---main
| | +---java
| | +---resources
| | | \---META-INF
| | | \---resources
| | | \---images
| | | placeholder_image.jpg
| | | placeholder_template.png
| | |
| | \---webapp
| | \---WEB-INF
| \---test
| +---java
| \---resources
我的战争有效组织是
+---META-INF
\---WEB-INF
\---classes
\---META-INF
\---resources
\---images
placeholder_image.jpg
placeholder_template.png
我想要提供的图像位于src/main/resources/META-INF/resources/images
文件夹中。
我使用 maven-war-plugin 打包这场战争。
如果我的战争在 http://localhost:8080/myapp/
路径下可用,那么这些图像将在我的本地计算机上的哪个 URL 下可用?
I'm trying to create a war that is to be deployed in an EAR and that should contain only images.
My war source organization is as follows :
+---src
| +---main
| | +---java
| | +---resources
| | | \---META-INF
| | | \---resources
| | | \---images
| | | placeholder_image.jpg
| | | placeholder_template.png
| | |
| | \---webapp
| | \---WEB-INF
| \---test
| +---java
| \---resources
and my war effective organization is
+---META-INF
\---WEB-INF
\---classes
\---META-INF
\---resources
\---images
placeholder_image.jpg
placeholder_template.png
The images I want to serve are in the src/main/resources/META-INF/resources/images
folder.
I package this war using maven-war-plugin.
Under which url will those images be available on my local machine, provided my war is indicated as available under the http://localhost:8080/myapp/
path ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有任何。 WEB-INF 中的内容不是静态提供的,
resources
用于类路径资源。您需要将图像(文件夹)直接放在webapp
下,或者添加一个提供内容的 servlet。None. Content from WEB-INF is not statically served,
resources
is for classpath resources. You need to put the images (folder) directly underwebapp
or add an servlet that serves the content.这取决于您是否在 Tomcat 7 或 Jetty 8 等 Servlet-3 兼容容器中部署
war
。如果是这样,您的资源应该在
http://localhost:8080/ 下可见myapp/images/...
。另请参阅这篇文章,其中唯一的区别是资源打包在
jar
中。对于jar
来说,此功能比对于WEB-INF/classes
更有意义,因为,就像第一个答案指出的那样,您应该简单地将资源直接放入>src/main/webapp
如果它们位于同一个 Maven 模块中。This depends on whether you deploy the
war
in a Servlet-3-compatible container like Tomcat 7 or Jetty 8.If so, your resources should be visible under
http://localhost:8080/myapp/images/...
.See also this post, where the only difference is that the resources are packaged in a
jar
. Forjar
s, this feature makes more sense than forWEB-INF/classes
, as, like the first answer points out, you should simply put your resources directly intosrc/main/webapp
if they are located in the same Maven module.