tags:

views:

688

answers:

4

When building my EJB project with maven, maven expects the ejb-jar.xml to be in META-INF/. However; I need to be able to put it in directoryA/META-INF.

maven-ejb-plugin doesn't seem to provide a parameter for specifying where ejb-jar.xml is.

Can you point me in the right direction?

+1  A: 

Indeed, the maven-ejb-plugin doesn't provide any parameter to change the location of the deployment descriptor which is expected to be available at META-INF/ejb-jar.xml (the location is hard coded in the EjbMojo) or the build will fail at packaging time when building EJB 2.X (which makes sense).

So, one way to achieve your goal would be to use the maven-antrun-plugin before the packaging phase to copy the content of directoryA (assuming directoryA was in a resources directory like src/main/resources and has been copied to target/classes) to the expected location (i.e. the root of target/classes) and do some clean up, something like this:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>prepare-package</phase>
      <configuration>
        <tasks>
          <copy todir="${project.build.outputDirectory}">
            <fileset dir="${project.build.outputDirectory}/directoryA"/> 
          </copy>
          <delete dir="${project.build.outputDirectory}/directoryA"/>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

I don't find this very clean but it works.

Pascal Thivent
I ended up having to use this method (even though I don't like it any more than you do.) Had to rearrange some of the calls (making a directory first, etc), but the basic idea worked. Thanks.
Jared
A: 

Wont the "outputDirectory" configuration property work (http://maven.apache.org/plugins/maven-ejb-plugin/ejb-mojo.html#outputDirectory)? I see that it has been suggested in the antrun example mentioned earlier; however, this config property is available in the ejb plugin-itself (see the link). Or, are you saying you ONLY want the ejb-jar.xml to be moved?

cjstehno
No - output directory would change the location of the output file. I need to change the location of the INPUT file (where it gets the file from, not where it puts the output when the build is complete.)
Jared
A: 

Plugin look for the ejb-jar.xml in the build.outputdirectory/META-INF as I could see in the pligin source file private static final String EJB_JAR_XML = "META-INF/ejb-jar.xml"; It is possible to copy reqiured ejb-xml using the resource plugin ....

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
    <execution>
        <id>copy-resources</id>
        <phase>validate</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
            <outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory>
            <resources>
                <resource>
                    <directory>${project.build.sourceDirectory}/META-INF</directory>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>

Xelast
A: 

I needed to do the same thing and got it to work by simply adding an additional resource directory to the 'build' section of the POM (which is in additon to the default location of java/main/resources):

<build>
    <resources>
        <resource>
            <directory>${project.basedir}/directoryA</directory>
        </resource>
    </resources>
...
</build>
Kenny Stainback