Including an external non mavanized jar in maven build and packaging

I said that before and will say again, maven sometimes sucks.

Its like your mother in low, you respect her because she brought the comfort into your life, you must live with her coz there is no other, but sometimes you really really wan'a kill her, and your at least comforted knowing she will probably be dismissed earlier then you and the sooner the better.

 

so what do you do if you have a jar you want to include in your build and packaging but you can't find it in any public repository?

you can't upload it to a local repository like nexus because your working on an open source projects with a distributed SCM and programmers are all over the world on different networks.

Your left with the good old ant days where you have to manualy download and include the jar in your source tree.

Today I had to use commons-validator-1.4 that is not released yet and couldn't find it in any snapshot repository, tried all apache repos but no trace of commons-validator-1.4-snapshot.

so i created a 'lib' folder in my source tree, placed the jar there and thought i could set it as a system scope dependency:

            <dependency>
                <groupId>commons-validator</groupId>
                <artifactId>commons-validator</artifactId>
                <version>1.4-SNAPSHOT</version>
                <scope>system</scope>
                <systemPath>${user.dir}/lib/commons-validator-1.4-SNAPSHOT.jar</systemPath>
            </dependency>
 

easy ha?

not so much, the BUILD SUCCESSFUL message is sometimes deceiving, build passes but system scope dependencies are not packaged by war plugin, I can see some logic in that but why not give the option to include system scope dependencies in war and ear packaging if you want to? go figure.

what I had to do is actualy install the jar to the local repository during the build process, so I change my simple lib folder to a maven module  pom packaging, placed the jar in its root folder and in its build section I installed commons-validator jar to the local repo using maven-install-plugin, and its done for every build. of cource i can make it under a maven profile but then every developer cloning the sources must know she has to install that before a build.

anyway, at least it works.

 

and this is my lib's module pom:

 

 <build>
        <plugins>
            <!-- localy install commons-validator-1.4.jar until it is released ,
                todo: see when its released -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install-commons-validator</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/commons-validator-1.4-SNAPSHOT.jar</file>
                            <groupId>commons-validator</groupId>
                            <artifactId>commons-validator</artifactId>
                            <version>1.4-SNAPSHOT</version>
                            <packaging>jar</packaging>
                            <createChecksum>true</createChecksum>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-commons-validator-source</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.basedir}/commons-validator-1.4-SNAPSHOT-sources.jar</file>
                            <groupId>commons-validator</groupId>
                            <artifactId>commons-validator</artifactId>
                            <version>1.4-SNAPSHOT</version>
                            <packaging>jar</packaging>
                            <classifier>source</classifier>
                            <createChecksum>true</createChecksum>
                            <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 

 

 


 

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com