Kevin
Kevin

Reputation: 4128

Automate packaging JSF composite components into JAR with Maven

I have a number of composite components within resources/components directory in a Maven WAR project. I wish to make my composite components reusable, and instead package them alone in a JAR (they may have associated ManagedBeans.

A number of existing questions, such as this one, address the same or a similar task. However, none specify how to use Maven to automate the process.

I would prefer to not use Ant.

Upvotes: 0

Views: 1166

Answers (2)

Kevin
Kevin

Reputation: 4128

This worked for me:

<resources>          
    <resource>
        <directory>src/main/webapp/resources</directory>
        <targetPath>META-INF/resources</targetPath>
  </resource>
  <resource>
        <directory>src/main/webapp/WEB-INF/</directory>
        <targetPath>META-INF</targetPath>
    </resource>          
</resources>

Making sure to have:

<packaging>war</packaging>

A also have the maven plugin enabled to allow Netbeans to recognise the project as being a web project:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
    </plugin>

Upvotes: 1

Jintian DENG
Jintian DENG

Reputation: 3202

I suggest using maven-antrun-pluin. Following is a verified example:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prepare-deploy-package</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <copy todir="${project.build.directory}/${project.build.finalName}/META-INF/resources" overwrite="true">
                                    <fileset dir="src/main/resources">
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Upvotes: 2

Related Questions