dev@glassfish.java.net

Re: maven2 directory layout questions

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Tue, 13 Nov 2007 15:09:33 -0800

On Nov 13, 2007, at 2:40 PM, Bill Shannon wrote:

> Jerome Dochez wrote:
>> On Nov 13, 2007, at 1:01 PM, Bill Shannon wrote:
>>> I'm converting the GlassFish "mail" module to the maven2 directory
>>> layout, as specified at
>>> http://wiki.glassfish.java.net/Wiki.jsp?page=V3WorkspaceStructure
>>> Rather than start with the CVS version of the module, I'm starting
>>> with the "real" master workspace, which I've migrated from Teamware
>>> to Mercurial. Ultimately I hope to publish it as a completely
>>> separate java.net project/module.
>> umh I already did some of that work at
>> https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/api/mail/
>> you should start from there probably...
>
> Um, as owner of the mail module, it would've been nice if I had been
> notified that you planned to do such work...
>
>> to checkout follow the engineering guide.
>
> It's on my list of things to figure out. I haven't gotten there yet.
>
>>> In addition to build the JavaMail mail.jar file, I also want to be
>>> able to build the JavaMail release zip file, which includes the
>>> mail.jar
>>> file, other jar files, documentation, javadocs, demo source code,
>>> etc.
>> in maven, these are several different jar files, you have the
>> source.zip the javadoc.zip and the binary.zip
>> are you particularly attached to your bundle format ?
>
> Yes. I want the transition to the new build system to be transparent
> to users of the JavaMail binary download bundle.

so you will need a specific maven package task, look at
http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html

>
>
>>> I haven't learned much about maven2 yet so I have some simple
>>> questions
>>> about the directory layout...
>>>
>>> 1. Where should I put the documentation? Is a top level "doc"
>>> directory ok?
>>>
>> where would it go in the packaged zip ?
>
> I put it in a top level "doc" directory.
so the easiest is to put it in src/main/resources/doc
>
>
>>> 2. Can I leave package.html and overview.html in the src/main/java
>>> directory tree?
>>>
>> yes
>>> 3. Where do I put sample/demo source code? When I make a JavaMail
>>> release, I want to include the demo source code in the zip file.
>>> And I want to be able to build the demos to make sure they build
>>> properly before release, but the resulting class files aren't
>>> included in the release. Most demos are simple, standalone,
>>> independent applications. Should I put them all in src/demo/java?
>>> Do I need a different directory under src for each one?
>>>
>> I put those files in the demo top level directory for now, I was
>> planning to revisit that later. I think in theory you should create
>> sub modules and so on but that seem very tedious to me.
>
> Extremely.
>
>>> From the same set of sources I build multiple jar files with
>>> different combinations of sources. Each jar file needs its
>>> own manifest and its own resource files. The manifest files
>>> need to be preprocessed to (e.g.) fill in the correct version
>>> number before use.
>>>
>> that would definitly force you into different sub-modules each with
>> its resources/pom.xml
>> something like :
>> mail/pom.xml (mail-api pom.xml)
>> mail/src/main/java (mail-api sources)
>> mail/demo/pom.xml (list of demo modules)
>> mail/demo/demo1/pom.xml
>> mail/demo/demo1/src/main/java/...
>> mail/demo/demo1/src/main/resources/...
>> mail/demo/demo2/pom.xml
>> mail/demo/demo2/src/main/java/...
>> mail/demo/demo2/src/main/resources/...
>> ...
>
> This isn't about the demos (although that's a problem too).
>
> I create imap.jar, smtp.jar, mail-api.jar, etc., and the content of
> (almost) all of those are included in mail.jar.
>
> I would really prefer to have one source tree, from which I can create
> multiple jar files. Is there really no way to do that with maven?
>
yes you can do that :

        mail/src//main/java (your shared sources)
        mail/src/main/resources (your shared resources)
        mail/smtp/pom.xml (sourceDirectory pointing to ../src/mainjava)
        mail/smtp/src/main/resources (your smtp specific resources)
        mail/imap/pom.xml (sourceDirectory pointing to ../src/main/java)
        mail/imap/src/main/resources (your imap specific resources)

> If not, how do I create the mail.jar file based on the content of
> other
> jar files?
>
> If I have to have sub-modules, how do I name them? src/imap/java?
> imap/src/main/java?
submodule should just be a directory inside your module's directory
and then
follow the same organization.

>
>
>>> 4. Should I put all these manifest and resource files under
>>> src/main/resources?
>> no you have to split them like described above.
>
> Yuck.
hopefully the example above is solving your problem in a better way...
>
>
>>> 5. Is there a way to preprocess these files before use, including
>>> changing their names? Or do the things in src/main/resources
>>> just get copied with no processing?
>> you can process files while copying them, look for example how to
>> process manifest files at
>> http://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html
>> With pom.xml I have in v3/pom.xml, all the api jar modules
>> automatically contains the license file and the customized
>> manifest, therefore your examples should probably not inherit the
>> org.glassfish.api:api pom.xml. In fact they probably don't need a
>> parent pom
>
> Right now I'm just trying to get the build to work using ant. I'll
> get back to figuring out maven some other day, at which point I'll
> figure out what the above means. :-)

In maven, pom can have a parent in which case they inherit some of the
parent properties. In this particular case, the pom.xml defined in the
v3/api directory defines the behaviour so that we get the license
automatically placed into META-INF and the right manifest entry. If
you want that behaviour, you could be a child of that pom OR if you
don't, do not have a parent pom.

1. For instance go to v3/api/connector directory and look at the
pom.xml, it's practically empty, it has just the parent, the module ID
and the developer name.

2. now do a mvn clean install

3. now check the content of of the artifact :
  jar -tvf target/connector-api-1.5.jar

it contains the META-INF/License and the manifest file has all the
right entries... how could this be done ? It comes from the parent
pom.xml which is in v3/pom.xml

this link http://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.htm
is just about customizing the manifest file with versions and such.

>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>