Search code examples
mavenpackagewar

Packaging separate jar file to war file in maven


I have created a web application using Java. According to the design, I have created a plugin for that web application. When I am releasing the package, I want to package that plugin's jar file in to the "WEB-INF/lib" directory. I am just copying the jar file manually. Instead of that, are there any capabilities to handle those things using maven? I don't want to add that plugin in to the web application as a dependancy.


Solution

  • You can specify it within the maven war plugin. Please see below.

    Let

    jar file -> jarfile.jar

    jar file path -> jarFilePath ( with reference to base dir )

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <webResources>
                <!--jarfile.jar file in to the WEB-INF/lib folder -->
                <resource>
                    <directory>jarFilePath</directory>
                    <includes>
                        <include>jarfile.jar</include>
                    </includes>
                    <targetPath>WEB-INF/lib</targetPath>
                </resource>
            </webResources>
        </configuration>
    </plugin>