문제

I'm developing a web application using Eclipse Juno and Maven-WTP plugin. This application has a header image and I also have two Maven profiles. Those profiles permit changing the header image, because they point to a different directory, where the image is located. That's how they are configured:

<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>

The idea is when I change the active profile in my .m2/settings.xml to have the header file changed as well. The active profile is configured like that:

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

If I change the active profile and do mvn clean install everything works like a charm in project's target directory. However, the problem comes with Maven-WTP plugin. This plugin is taking the file from webapp/images directory, and looks like when I change the active profile is not getting the new one. It seems the WTP plugin is not updating the file here, so I get the old one displayed in the browser, even I do a clean install. This is my pom.xml configuration:

<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>

Does anybody know about that?

도움이 되었습니까?

해결책 2

The Maven Eclipse WTP Plugin is getting the data to deploy from webapp directory. The clue is that this directory is not being cleaned when executing mvn clean install, because Maven only cleans target directory. The trick is forcing Maven to clean the resources I'm going to update too.

<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>

다른 팁

You probably will need to update your Maven project configuration via:

right click on your project -> Maven -> Update Project

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top