简体   繁体   English

如何使用Maven和Eclipse将资源复制到webapp目录?

[英]How do I copy resources to webapp directory using Maven and Eclipse?

I'm following an old example on Jetty: Quick Start - Servlets and .jsp pages (hosted within the same .jar as the embedder 我正在关注Jetty上的一个旧示例: 快速入门-Servlet和.jsp页面(与嵌入程序托管在同一.jar中)

It's showing me how to serve up resource files from the web app directory. 它向我展示了如何从Web应用程序目录提供资源文件。

The absolute path at run time appears to be: 运行时的绝对路径似乎是:

C:\Projects\appname\target\classes\com\companyname\product\webapp

I'd like to keep the source in another location, perhaps: 我想将源保存在另一个位置,也许是:

C:\Projects\appname\resources

I'm using maven, and do most of my development in Eclipse. 我正在使用maven,并在Eclipse中进行大部分开发。 What is the best practice for how to set this up? 如何进行最佳设置是什么? Should I use a maven plugin to copy the resources to the output directory at build time? 我应该在构建时使用Maven插件将资源复制到输出目录吗? Are my project source and output folders set up to any recognizable practice? 我的项目源和输出文件夹是否设置为任何可识别的做法?

I've just set up things so that they run so far, I'm open to suggestions on improvement. 我已经设置好了东西,以便它们可以运行到现在为止,我乐于接受有关改进的建议。

You can try follow maven directory layout: 您可以尝试遵循maven目录布局:

https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

C:\Projects\appname\src\main\webapp
C:\Projects\appname\src\main\java
C:\Projects\appname\src\main\resources
C:\Projects\appname\pom.xml

If you are using eclipse kepler, enable maven nature on your project. 如果您使用的是eclipse kepler,请在您的项目中启用Maven性质。 Then go to "Server" and add a jetty server. 然后转到“服务器”并添加码头服务器。 And to run your project, simply click "Run As" -> "Run on Server". 要运行您的项目,只需单击“运行方式”->“在服务器上运行”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM