0

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.

Community
  • 1
  • 1
Kevin
  • 4,070
  • 4
  • 45
  • 67

2 Answers2

2

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>
Jintian DENG
  • 3,152
  • 20
  • 22
  • I'm having an issue: when building, the uncompressed output folder contains the correct resources, however, the compressed JAR version is missing them. – Kevin Jan 25 '13 at 05:56
  • Do you have any extra configuration on maven-war-plugin? – Jintian DENG Jan 25 '13 at 07:56
1

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>
Kevin
  • 4,070
  • 4
  • 45
  • 67