将现有的 Web 应用程序文件结构转换为 Maven 文件结构?

发布于 2024-10-04 05:11:33 字数 431 浏览 0 评论 0原文

我有一个创建 .war 文件的现有 Web 应用程序。我想将目录结构转换为maven的约定。我有点失落。

特别是,由 ant 目标创建的当前 .war 不会将 site/statics 目录子树中的任何内容复制到 .war 中;这是由另一个不同的 ant 目标复制的。

但如果我想从 maven 运行 jetty(我确实这么做了!),我需要将 site/statics/**/. 复制到 maven 的 target 中的某个位置代码>目录。鉴于 Maven 的约定,我不知道如何做到这一点。

谢谢。

以下是 Eclipse 屏幕截图(抱歉)的现有目录结构:

I have an existing web application that creates a .war file. I want to convert the directory structure to maven's conventions. And I'm a bit lost.

In particular, the current .war, created by an ant target, doesn't copy to the .war anything in the site/statics directory subtree; this is copied by another, different ant target.

But if I want to run, e.g., jetty from maven (and I do!), I'll need to copy site/statics/**/. to somewhere in maven's target directory. I don't know how to do that given maven's conventions.

Thanks.

Here's the existing directory structure as a (sorry) screenshot form Eclipse:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-10-11 05:11:33

您最好遵循 maven 默认目录结构,或者如果您坚持使用自己的目录结构,则需要分别配置您的 maven .pom 文件。

此处解释了默认的 Maven war 插件目录结构及其用法< a href="http://maven.apache.org/plugins/maven-war-plugin/usage.html" rel="noreferrer">此处。

默认情况下,${basedir}/src/main/webapp 是放置 jsp 文件和其他静态或动态文件的位置,这些文件应位于 war 目录根目录下。要更改此默认结构,您需要向 pom.xml 添加一些配置。查看此页面中提供的不同选项在 此页面 的示例使用它们。

您可以在 pom 中使用以下设置,而不是使用脚本复制外部静态文件:

<plugins>
  ...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <webResources>
        <resource>
          <directory>/absolute/path/to/external/static/</directory>
        </resource>
      </webResources>
    </configuration>
  </plugin>
  ...
</plugins>

目录可以是相对于您的 pom 的路径或绝对路径(这使您的 pom 不可移植)或使用 ${xxx} 进行参数化

You would better follow maven default directory structure or if you insist to use your own you need to configure your maven .pom file respectively.

Default Maven war plugin directory structure is explained here and its usage here.

By default ${basedir}/src/main/webapp is where you should put you jsp files and other static or dynamic files that should go to war directory root. To change this default structure you need to add some configuration to you pom. Have a look at different options available at this page and at this page for an example of using them.

Instead of copying your external static file with a script you can use following setting in you pom:

<plugins>
  ...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <webResources>
        <resource>
          <directory>/absolute/path/to/external/static/</directory>
        </resource>
      </webResources>
    </configuration>
  </plugin>
  ...
</plugins>

Directory can be a path relative to you pom or an absolute path (which makes you pom unportable) or be parametrized using ${xxx}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文