【问题标题】:Eclipse Maven WTP plugin not refreshing resources when switching profileEclipse Maven WTP插件在切换配置文件时不刷新资源
【发布时间】:2013-01-14 10:39:41
【问题描述】:

我正在使用 Eclipse Juno 和 Maven-WTP 插件开发一个 Web 应用程序。这个应用程序有一个标题图像,我也有两个 Maven 配置文件。这些配置文件允许更改标题图像,因为它们指向图像所在的不同目录。这就是它们的配置方式:

<profile>
    <id>local</id>
    <properties>
        <imagen.cabecera.dir>src/main/resources/styles/headers/example1</imagen.cabecera.dir>
    </properties>
</profile>

<profile>
    <id>local2</id>
    <properties>
        <imagen.cabecera.dir>src/main/resources/styles/headers/example2</imagen.cabecera.dir>
    </properties>
</profile>

这个想法是当我更改我的 .m2/settings.xml 中的活动配置文件以更改头文件时。活动配置文件的配置如下:

<activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
    <activeProfile>local</activeProfile>
</activeProfiles>

如果我更改活动配置文件并执行mvn clean install,那么在项目的目标目录中,一切都会像魅力一样工作。但是,问题来自 Maven-WTP 插件。这个插件从webapp/images 目录中获取文件,看起来当我更改活动配置文件时没有获取新配置文件。似乎 WTP 插件没有更新这里的文件,所以我在浏览器中显示了旧的,即使我做了clean install。这是我的 pom.xml 配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>process-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <resources>
                    <resource>
                        <directory>${imagen.cabecera.dir}</directory>
                        <includes>
                            <include>cabecera.jpg</include>
                        </includes>
                        <targetPath>${project.build.directory}/header</targetPath>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>default-war</id>
            <configuration>
                <webResources>
                    <resource>
                        <directory>${project.build.directory}/header</directory>
                        <includes>
                            <include>cabecera.jpg</include>
                        </includes>
                        <targetPath>/images</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </execution>
    </executions>
</plugin>

有人知道吗?

【问题讨论】:

    标签: eclipse maven eclipse-wtp maven-eclipse-plugin


    【解决方案1】:

    您可能需要通过以下方式更新您的 Maven 项目配置:

    右键单击您的项目 -> Maven -> 更新项目

    【讨论】:

      【解决方案2】:

      Maven Eclipse WTP 插件 正在从 webapp 目录获取要部署的数据。线索是执行mvn clean install时没有清理这个目录,因为Maven只清理target目录。诀窍是forcing Maven to clean 我也要更新的资源。

      <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>2.5</version>
          <configuration>
              <filesets>
                  <fileset>
                      <directory>src/main/webapp/images</directory>
                      <includes>
                          <include>cabecera.jpg</include>
                      </includes>
                  </fileset>
              </filesets>
          </configuration>
      </plugin>
      

      【讨论】:

        猜你喜欢
        • 2017-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-04
        • 1970-01-01
        • 1970-01-01
        • 2017-01-20
        相关资源
        最近更新 更多