tags:

views:

48

answers:

3

Is there a way to put dependency of a war not in WEB-INF/lib but in out custom folder?

I'm using Maven 2

Hi, what i need is that from list of dependencies of a war only one artifact should be placed not in WEB-INF/lib but in WEB-INF/bundles/ and others dependencies should be places in WEB-INF/lib

thx

THX to everybody, i can't update to Maven 2.1 so i did it through maven-antrun plugin )

+1  A: 

Maven war plugin supports extensive customization. Not clear from your question, what exactly you want, but this page should hopefully help.

Raghuram
Hi, what i need is that from list of dependencies of a war only one artifact should be placed not in WEB-INF/lib but in WEB-INF/bundles/ and others dependencies should be places in WEB-INF/lib
Maven war plugin won't help here, it doesn't support such an option
seanizer
A: 

Where do you want to put these libraries? You have to be carefull, as the war structure defines the WEB-INF/lib as the directory for third-parties libraries. All *.jar files located in this directory will be loaded in the Classpath by the container (such as Tomcat).

Changing this directory can be harmful for your application!

That's why I am not aware of a configuration parameter for the Maven WAR Plugin that allow you to change this WEB-INF/lib directory.

If you really know what you are doing, you can try to create your own WAR using an assembly.

romaintaz
+2  A: 

I think what you need to do is make the dependency provided and copy it using mvn copy-dependencies. Here is an example that does that with apache commons / lang:

<dependencies>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copydep</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <inherited>false</inherited>
                    <configuration>
                        <includeArtifactIds>commons-lang</includeArtifactIds>
                        <outputDirectory>$project.build.directory/${project.build.finalName}/web-inf/bundles</outputDirectory>
                    </configuration>
                </execution>
            </executions>
            <configuration>
            </configuration>
        </plugin>
    </plugins>
</build>

($project.build.directory/${project.build.finalName} is the work folder that is used to assemble the war)

seanizer
I'm using Maven 2.0.9 and it didn't place artifact in any directory i specify (( I didn't understand why :)
Do you know if prepare-package phase exists in Maven 2.0.9 ?
prepare-package definitely did exist back then. maybe you could run the command with the -XD flag, pipe it to a file and post the output on pastebin, then we could see what's happening: ` mvn clean install -X > myfile.txt`
seanizer
Actually, `prepare-package` is only available in Maven 2.1 and above (http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html). Still, this is the best suggestion so far (and I'm not sure there is a better one). +1
Pascal Thivent
well okay, it should be possible to put it in the package or process-classes phase, then. (package is probably not a good idea as old maven versions are not reliable concering execution order in one phase)
seanizer
Yeah, process-classes should work. Or just upgrade to Maven 2.2.1^w 3.0 :)
Pascal Thivent