Maven Web 资源问题

发布于 2024-12-04 04:57:51 字数 428 浏览 4 评论 0原文

我有一个 Maven Web 项目,并且在 src\main\webapp\ 文件夹下有一些 CSS 和 Javascript 文件。我经常对这些文件进行更改,并且希望快速看到我的更改。如果我运行maven install,由于项目依赖性,它需要很长时间。有时我只想更改 CSS 文件中的一行代码,而不想重新编译其他所有内容。我有一个 Maven 插件,可以将输出 war 文件发布到我的 JBoss 实例。理想情况下,我想运行一个 Maven 执行脚本,它将快速将我的 Web 资源复制到输出文件夹并重新部署更改后的 war 文件,而无需重新编译其他所有内容。

我尝试调用 generate-resources 目标,但似乎没有在 src\main\webapp 目录中查找,因为它期望我的资源位于 src\main\resources 文件夹下。我在这里缺少什么?

谢谢

I have a Maven web project and I have some CSS and Javascript files under the src\main\webapp\ folder. I constantly make changes to those files and would like to see my changes quickly. If I run maven install, it takes ages due to project dependencies. Sometimes all I want to change is one line of code in my CSS file and do not want to recompile everything else. I have a maven plugin that publishes my output war file to my JBoss instance. Ideally, I would like to run a maven execution script that will quickly copy my web resources to the output folder and reploy the changed war file without recompiling everything else.

I tried invoking the generate-resources goal but that doesn't seem to look in the src\main\webapp directory as it is expecting my resources to be under the src\main\resources folder. What am I missing here?

Thanks

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

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

发布评论

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

评论(2

薯片软お妹 2024-12-11 04:57:51

如果您想在生成资源插件期间添加更多要复制的资源,您可以更改构建使用的资源文件夹。 project.build.resources 属性控制在哪些文件夹中搜索资源。您可以添加:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <directory>src/main/webApp</directory>
        <includes>
          <include>*.css</include>
          <include>*.js</include>

然后运行 ​​mvn resources 来复制文件。

这种方法是在任何构建的资源阶段始终复制这些文件。您可以通过使用 copy-resources 目标而不是资源来解决此问题。在这种情况下,您将使用以下配置:

<build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>copy-web-resources</id>
            <!-- here the phase you need -->
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/webApp</outputDirectory>
              <resources> 
                <resource>
                 <directory>src/main/webApp</directory>
                 <includes>
                   <include>*.css</include>
                   <include>*.js</include>

然后您可以运行 mvn resources:copy-resources 来复制文件。

If you want to add more resources to be copied during the generate-resources plugin, you can change the resources folders used by your build. The project.build.resources property controls which folders are searched for resources. You could add:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <directory>src/main/webApp</directory>
        <includes>
          <include>*.css</include>
          <include>*.js</include>

You would then run mvn resources to copy the files.

This approach is that these files will always be copied during the resources phase of any build. You can get around this by using the copy-resources goal instead of resources. In this case you would use the following configuration:

<build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>copy-web-resources</id>
            <!-- here the phase you need -->
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/webApp</outputDirectory>
              <resources> 
                <resource>
                 <directory>src/main/webApp</directory>
                 <includes>
                   <include>*.css</include>
                   <include>*.js</include>

You could then run mvn resources:copy-resources to copy the files.

薄荷→糖丶微凉 2024-12-11 04:57:51

我认为您可以通过使用 war:war 目标来实现这一目标。这应该会在输出文件夹中为您生成一个 war 文件,而无需重新编译源代码。

I think you could accomplish this by using the war:war goal. This should generate a war file in the output folder for you without re-compiling the source.

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