Maven module for static files

I have a web application with spring and maven. The application is split into maven modules. I have a "application-web" module that generates a war. Another application-ear module that creates an ear. And one more "application-static" with css, js and images that generate a zip file.

This will be the outline of my application:

  • applications
    • application-web (java code)
    • app ear
    • application-static (css, js and images)
    • applied resources (language properties)

I want to deploy eclipse use files from a "static" module, instead of using the files in the "application / src / main / webapp" directory. How can i do this? Is it possible?

+1


source to share


3 answers


Don't waste time unpacking resources, everything works out of the box:

  • Resource bundles: they are always loaded from the classpath, whether they are exploded ( WEB-INF/classes

    ) or compressed ( WEB-INF/lib

    )
  • Serving static resources: bundle them into a JAR and use Tomcat (Servlet 3.0) function to serve from META-INF/resources

    , see here, or use Spring's built-in element mvc:resources

    .


Just add the dependency snippets to your WAR POM and you're done.

+1


source


You can use the maven dependency plugin to unpack your static resources included in the zip file using the following:

In your app-web.pom



<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-resources</id>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <outputDirectory>resources</outputDirectory>
                <includeArtifactIds>application-static</includeArtifactIds>
                <includeGroupIds>your group id</includeGroupIds>
                <includes>**/*.js,**/*.css</includes>
            </configuration>
        </execution>
    </executions>
</plugin

      

0


source


This work:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <excludeTypes>pom</excludeTypes>
                        <includeArtifactIds>application-static</includeArtifactIds>
                        <includeGroupIds>com.foo.foo.application</includeGroupIds>
                        <outputDirectory>src/main/webapp</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>${project.artifactId}-${project.version}</finalName>
</build>

      

But I have another problem as this solution only copies static files when executing a clean package. If I run a web app with eclipse and I make changes to the js file in the static app, the changes don't take effect until I run a clean package. Any solution for this?

0


source







All Articles