How do I change the location of ejb-jar.xml in my maven project?

10,089

Solution 1

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.

Solution 2

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>

Solution 3

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>
Share:
10,089
Jared
Author by

Jared

I work for Amazon Web Services. Opinions expressed on social media are my own.

Updated on June 05, 2022

Comments

  • Jared
    Jared almost 2 years

    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?