1

I've been doing this for all of the jar files that my Spring MVC project needs:

call mvn install:install-file -DgroupId=vegetables -DartifactId=potatoes -Dversion=1.0 -Dfile=vegetables-1.0.jar  -Dpackaging=jar -DgeneratePom=true

Recently I must have exceeded some limit on how many dependencies you can list in your pom.xml file because I got an error that said:

Your command line is too long

So I removed some dependencies from the pom.xml that my project no longer uses and I was able to run the project with maven again.

My question is, should I put install all jar files into my Maven repository as I have been doing so far? Or should I put some of them into the WEB-INF/lib directory?

What's the best practice here?

Vegan
  • 11
  • 1
  • 2
  • You much dependencies did your `pom.xml` have when the error occured? – splash Jul 04 '11 at 11:51
  • 1
    I don't have an answer as to best practice... but I can tell you than many shells (Windows cmd.exe and Unix's ksh, just for example) have a 4K limit on length of a command. We ran into this with a Weblogic server command-line. We ended up repackaging our ubiquitous (but reasonably static) libraries like xerces, xalan, apache commons, apache collections, etc, etc into one common.jar file, and we also simplified and shortened our server directory names. It took a bit of mucking around, but everthing starts reliably now. – corlettk Jul 04 '11 at 11:55
  • @splash: I had about 50 dependencies listed in `pom.xml` when the error occurred. – Vegan Jul 04 '11 at 12:25
  • @corlettk: Interesting. I didn't realize it might be an error coming from the shell. I'm using `cmd.exe` on `Windows 7` and didn't know there was a `4k` limit. – Vegan Jul 04 '11 at 12:26

3 Answers3

10

I've been doing the same that you do with the command line, but by configuring maven-install-plugin in my POM (please read the note at the end):

     <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <executions>
                <execution>
                    <id>install-vegetables</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <file>${project.basedir}/lib/vegetables-1.0.jar</file>
                        <groupId>vegetables</groupId>
                        <artifactId>potatoes</artifactId>
                        <version>1.0</version>
                        <packaging>jar</packaging>
                    </configuration>
                </execution>
                <execution>
                    <id>install-minerals</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <file>${project.basedir}/lib/minerals-1.0.jar</file>
                        <groupId>minerals</groupId>
                        <artifactId>rocks</artifactId>
                        <version>1.0</version>
                        <packaging>jar</packaging>
                    </configuration>
                </execution>
            </executions>
        </plugin>

It is much less efficient, because files get installed over and over, but it is much less annoying than making it manually. Anyway, I think you should give it a try.

Martín Schonaker
  • 7,273
  • 4
  • 32
  • 55
  • Could the element be changed so that install can be run explicitly, separate from the main build workflow? The down-side would be potentially forgetting to run it when a dependency jar is updated, but I would rather have the option of a faster build. – David Mason Mar 31 '12 at 12:37
  • 1
    I don't know. But certainly you could use a profile for this. – Martín Schonaker Mar 31 '12 at 16:18
3

All your dependencies should reside under the local repository. According to the Maven convention/best practices, you should not keep jar files in your project.

Convert your project to a fully war based Maven project. This will place all your dependencies (jar files) under your webapp's WEB-INF/lib directory. Thus you will not have to worry about long paths.

carlspring
  • 31,231
  • 29
  • 115
  • 197
0

You just need to add the dependencies in your pom.xml file, no need to install them manually. Maven will download the libraries and put it in your local repository whenever needed. Only if you want to use third party(custom) libraries, you may go for installing it in your local repository.

Sunil Manheri
  • 2,313
  • 2
  • 18
  • 19