You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by rdiddly <rd...@mac.com> on 2013/06/11 22:26:54 UTC

Using Maven to produce an EAR

Hello Maven mavens,

Forgive me if this is a duplicate. I sent it by email, but didn't see it
show up on the Nabble site, so I don't know if sending it to the list via
email works or not.

Good documentation on the maven ear plugin is not easy to find. Most posts
are from 2005.

I've got a multi-module POM. It has 6 sub-modules:

client.war
client-ejb.jar
admin.war
common-ejb.jar
app.ear
command.jar

I want to build client.war, client-ejb.jar, admin.war, and common-ejb.jar
into bundle.ear. common-ejb.jar has a compile time dependency on
thirdparty.jar (which is in my local repository). (command.jar is a
command-line java utility class that's used to execute jobs from a remote
client.)

I can build all of the sub-modules without any problems. Here's my pom to
build the ear (missing the open/close tags from XML, using ':' to separate
opening tag from content):

project
  modelVersion:4.0.0/modelVersion
  parent
    groupId:com.company/groupId
    artifactId:jewels/artifactId
    version:1.0-SNAPSHOT/version
  /parent
  groupId:com.company/groupId
  artifactId:bundle/artifactId
  version:1.0-SNAPSHOT/version
  packaging:ear/packaging
  
  name:bundle/name

  properties
    project.build.sourceEncoding:UTF-8/project.build.sourceEncoding
  /properties
  
  dependencies
    dependency
      groupId:com.company/groupId
      artifactId:client/artifactId
      version:1.0-SNAPSHOT/version
      type:war/type
    /dependency
    dependency
      groupId:com.company/groupId
      artifactId:client-ejb/artifactId
      version:1.0-SNAPSHOT/version
      type:ejb/type
    /dependency
    dependency
      groupId:com.company/groupId
      artifactId:admin/artifactId
      version:1.0-SNAPSHOT/version
      type:war/type
    /dependency
    dependency
      groupId:com.company/groupId
      artifactId:common-ejb/artifactId
      version:1.0-SNAPSHOT/version
      type:ejb/type
    /dependency
  /dependencies

  build
    plugins
      plugin
        groupId:org.apache.maven.plugins/groupId
        artifactId:maven-ear-plugin/artifactId
        version:2.8/version
        configuration
          modules
            jarModule
              groupId:third.party/groupId
              artifactId:thirdparty/artifactId
              bundleDir:lib/bundleDir
            /jarModule
          /modules
        /configuration
      /plugin
    /plugins
  /build
/project


I found that if I didn't use the jarModule in the configuration,
thirdparty.jar was put into the root directory of the ear instead of in the
lib folder (which is where I believe I want it), so I added the jarModule
block to specify that the thirdparty.jar should be put in the lib directory.
It is now put in the lib directory. Great. But, it's also in the root
directory.

I'm sure I'm doing something wrong, but it's hard to tell what given the
dearth of good examples.

Can anyone lend some assistance?

Thanks,
Richard

P.S. I'm in the very early stages of trying to move this project from Ant to
Maven. If there's anything about what you see here that you think I should
be doing differently (not that I've given the whole story, but from this
excerpt), please don't hesitate to let me know.



--
View this message in context: http://maven.40175.n5.nabble.com/Using-Maven-to-produce-an-EAR-tp5759041.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Maven to produce an EAR

Posted by Laird Nelson <lj...@gmail.com>.
On Wed, Jun 12, 2013 at 7:17 AM, rdiddly <rd...@mac.com> wrote:

> Thanks Laird, that did the trick. BTW, I didn't specify the dependency in
> the
> EAR's pom. It's specified in the EJB-jar's pom and that dependency is
> apparently being picked up when building the EAR.
>

There you go.  If it helps, my .ear file pom.xmls usually only have EJB
modules (.wars, EJBs) listed in them; everything else is included
transitively.

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Using Maven to produce an EAR

Posted by rdiddly <rd...@mac.com>.
Thanks Laird, that did the trick. BTW, I didn't specify the dependency in the
EAR's pom. It's specified in the EJB-jar's pom and that dependency is
apparently being picked up when building the EAR.



--
View this message in context: http://maven.40175.n5.nabble.com/Using-Maven-to-produce-an-EAR-tp5759041p5759127.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Maven to produce an EAR

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, Jun 11, 2013 at 1:26 PM, rdiddly <rd...@mac.com> wrote:

> I found that if I didn't use the jarModule in the configuration,
> thirdparty.jar was put into the root directory of the ear instead of in the
> lib folder (which is where I believe I want it), so I added the jarModule
> block to specify that the thirdparty.jar should be put in the lib
> directory.
> It is now put in the lib directory. Great. But, it's also in the root
> directory.
>

You're probably missing the defaultLibBundleDir configuration option,
documented here:
http://maven.apache.org/plugins/maven-ear-plugin/ear-mojo.html#defaultLibBundleDir

Here's more or less what you want:

<dependencies>
  <dependency>
    <groupId>whatever</groupId>
    <artifactId>someWar</artifactId>
    <version>someVersion</version>
    <type>war</type>
  </dependency>

  <dependency>
    <groupId>whatever</groupId>
    <artifactId>someEJB</artifactId>
    <version>someVersion</version>
    <type>ejb</type>
  </dependency>

  <dependency>
    <groupId>whatever</groupId>
    <artifactId>*someOrdinaryJar*</artifactId>
    <version>someVersion</version>
*    <!-- look, ma, no type element -->*
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <artifactId>maven-ear-plugin</artifactId>
      <configuration>
*        <defaultLibBundleDir>lib</defaultLibBundleDir>*
        *<version>6</version>* <!-- Java EE version; I presume you want 6
-->
      </configuration>
    </plugin>
  </plugins>
</build>

No modules necessary (at this level of configuration); no other
configuration.

Of note: the version parameter defaults to something godawful like 1.3,
which is why you have to specify it here.

The defaultLibBundleDir has no default, so you have to specify "lib".  I
regard both of these things as bugs.

Hope that helps you out.

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Using Maven to produce an EAR

Posted by rdiddly <rd...@mac.com>.
A clean build revealed many problems building the different artifacts due to
other small changes along the way. I'll have to do this more frequently as I
develop this mechanism. I have resolved each of those issues and you were
right, the jar got removed from the root. Next I will try the default lib
approach.



--
View this message in context: http://maven.40175.n5.nabble.com/Using-Maven-to-produce-an-EAR-tp5759041p5759125.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Maven to produce an EAR

Posted by Wayne Fay <wa...@gmail.com>.
> I can build all of the sub-modules without any problems. Here's my pom to
> build the ear (missing the open/close tags from XML, using ':' to separate
> opening tag from content):

Don't bother with this next time. Just post the XML. (Why did you feel
the need to strip the tags? Nabble fixed their code so xml should pass
thru properly.)

> I found that if I didn't use the jarModule in the configuration,
> thirdparty.jar was put into the root directory of the ear instead of in the
> lib folder (which is where I believe I want it), so I added the jarModule
> block to specify that the thirdparty.jar should be put in the lib directory.
> It is now put in the lib directory. Great. But, it's also in the root
> directory.

Most likely you have not run "mvn clean" in a while so the jar is
still in /target and thus its showing up in the root directory. I bet
it will only be in lib if you run "mvn clean package" instead. Try it
and report back.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org