How do I change the location of ejb-jar.xml in my maven project?
When building my EJB project with mave开发者_如何学编程n, 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?
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.
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>
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>
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?
精彩评论