tags:

views:

390

answers:

3

I am trying to remove a file from a dependency jar that I am including in my war file in maven. I am deploying the war to JBoss 5.1 and the jar in question contains a persistence.xml file that I don't want.

Here's what is going on:

my-webapp.war
|
`-- WEB-INF
    |
    `-- lib
        |
        `-- dependency.jar
            |
            `-- META-INF
                |
                `-- persistence.xml

When I am building my war, I want to remove persistence.xml Any one have any idea if this can be done easily?

+1  A: 

I don't believe this is possible. You can exclude dependent jars (see this), but not specific files in dependent jars.

Taylor Leese
A: 

Not available out of the box AFAIK, you'll have to use the Maven AntRun plugin after package to do a few dirty things:

  • unzip the war in a temp directory
  • unzip the dependency in another temp directory
  • delete the file from the dependency
  • zip the temp directory of the dependency back into a jar
  • move the dependency back in the temp directory of the war
  • zip the temp directory of the webapp back into a war
  • delete the temp directory of the dependency
  • delete the temp directory of the webapp

The following resources might help


Now, if the problem is that JBoss is deploying the persistence unit defined in the persistence.xml (and you don't want that), there might be a better solution. It seems that you can declare files to ignore in a jboss-ignore.txt file, for example:

WEB-INF/lib/dependency.jar/META-INF/persistence.xml

The feature is there, but I've never used it.

See

Pascal Thivent
A: 

I guess you would have to use the maven shade plugin (see link below)

Either build an Über-jar that includes your dependency minus the persistence-xml or just transform the dependency into something new that does not have the persistence.xml.

This should be the way to go:

http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html

Sean

seanizer
I thought about that but how would you plug this in the build? How would you tell the maven war plugin to pick the überjar instead of the "real" dependency.
Pascal Thivent
add a classifier to the dependency of the war plugin. add a deploy lifecycle that deploys the uberjar to your build. Actually, a local install will probably do. Take a look at http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.htmlSean
seanizer