You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Roberto Castro <ro...@cetip.com.br> on 2004/08/30 15:36:11 UTC

Compiling java sources codes from more than one directory

Hi, in my project, java source codes are in more than one subdirectory, like this:
--Source
     |
     +-Dir1
         |
         +subdir1
         |   + . . .
         |
         +subdir2
             + . . .
I tried to configure "project.xml" this way:
	<build>
		<sourceDirectory>Source/Dir1/**</sourceDirectory>

But, maven was not able to find java source codes.
Is there a way to compile all this codes in one subproject?
	Thanks in advance for the help,


     Roberto de Castro 
     Analista de Suporte 
     Cetip - Desus Rio de Janeiro 
     +55 21 2276-7439 
     mailto:robertoc@cetip.com.br 


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


Re: Compiling java sources codes from more than one directory

Posted by Christian Mouttet <ch...@keller-verlag.de>.
Try setting the "main" src in project.xml, e.g.
<sourceDirectory>${basedir}/Source/Dir1/subdir1</sourceDirectory>

Add other source dirs to maven.compile.src.set in maven.xml:

  <preGoal name="java:compile">
    <ant:path id="mysubdir" location="${basedir}/Source/Dir1/subdir2"/>
    <m:addPath id="maven.compile.src.set" refid="mysubdir"/>
  </preGoal>

Maybe you can build a loop over several "extra" subdirs. I don't know if it 
works, but adding a single "extra" source dir works very well. The name of 
the id 'mysubdir' is up to you.

Hope it helps

-Christian

Am Montag, 30. August 2004 15:36 schrieb Roberto Castro:
> Hi, in my project, java source codes are in more than one subdirectory,
> like this: --Source
>
>      +-Dir1
>
>          +subdir1
>
>          |   + . . .
>
>          +subdir2
>              + . . .
> I tried to configure "project.xml" this way:
> 	<build>
> 		<sourceDirectory>Source/Dir1/**</sourceDirectory>
>
> But, maven was not able to find java source codes.
> Is there a way to compile all this codes in one subproject?
> 	Thanks in advance for the help,
>
>
>      Roberto de Castro
>      Analista de Suporte
>      Cetip - Desus Rio de Janeiro
>      +55 21 2276-7439
>      mailto:robertoc@cetip.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org

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


Re: Compiling java sources codes from more than one directory

Posted by dan tran <da...@gmail.com>.
My bad!!!

Total agree with code generation scenarios

-D


On Sat, 4 Sep 2004 08:48:20 -0700, David Jencks <da...@yahoo.com> wrote:
> Generally plugins that generate additional source (javacc, xmlbeans,
> presumably xdoclet for a few) generate the source into a clearly
> labelled subdirectory of target and add this to the source path
> themselves.
> 
> I don't see any reason to allow "static" configuration of multiple
> source directories.  I do think that an easier-to-find guide on "how to
> write a code generation plugin that adds the generated source to the
> source path" might be a good idea.
> 
> thanks
> david jencks
> 
> 
> 
> On Sep 4, 2004, at 2:13 AM, Geoffrey wrote:
> 
> > If some sources are generated (for example with JAXB, GUI builders,
> > ...),
> > it is a good idea to keep them separated from the normal sources (to
> > be able
> > to clean them etc),
> > so it seems logical to me that Maven includes the option directly to
> > have
> > several source directories.
> > Having some sources being generated is not a valid reason to have
> > separate
> > module I think.
> >
> > But maybe this should be looked at together with RMI stub generation
> > and other binary class generators (jsp precompilation?).
> > It would be nice if there is a general system to plugin plugins that
> > generate sources
> > or plugins that generate class files.
> >
> > --
> > With kind regards,
> > Geoffrey
> >
> > "dan tran" <da...@gmail.com> schreef in bericht
> > news:c38ad92d04083007045d245b83@mail.gmail.com...
> >> Roberto,
> >>
> >> Maven discourages from this kind of build practice, unless you are
> >> willing
> > to
> >> do it your self, by combining multiple source directories into one via
> >> preGoal of
> >> java:complile.
> >>
> >> The correct way is to break your project into multiple projects and
> >> use Multiproject plugin to build them.
> >>
> >> -D
> >>
> >>
> >>
> >> On Mon, 30 Aug 2004 10:36:11 -0300, Roberto Castro
> >> <ro...@cetip.com.br> wrote:
> >>> Hi, in my project, java source codes are in more than one
> >>> subdirectory,
> > like this:
> >>> --Source
> >>>     |
> >>>     +-Dir1
> >>>         |
> >>>         +subdir1
> >>>         |   + . . .
> >>>         |
> >>>         +subdir2
> >>>             + . . .
> >>> I tried to configure "project.xml" this way:
> >>>        <build>
> >>>                <sourceDirectory>Source/Dir1/**</sourceDirectory>
> >>>
> >>> But, maven was not able to find java source codes.
> >>> Is there a way to compile all this codes in one subproject?
> >>>        Thanks in advance for the help,
> >>>
> >>>     Roberto de Castro
> >>>     Analista de Suporte
> >>>     Cetip - Desus Rio de Janeiro
> >>>     +55 21 2276-7439
> >>>     mailto:robertoc@cetip.com.br
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>> For additional commands, e-mail: users-help@maven.apache.org
> >>>
> >>>
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

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


Re: Compiling java sources codes from more than one directory

Posted by David Jencks <da...@yahoo.com>.
Generally plugins that generate additional source (javacc, xmlbeans, 
presumably xdoclet for a few) generate the source into a clearly 
labelled subdirectory of target and add this to the source path 
themselves.

I don't see any reason to allow "static" configuration of multiple 
source directories.  I do think that an easier-to-find guide on "how to 
write a code generation plugin that adds the generated source to the 
source path" might be a good idea.

thanks
david jencks

On Sep 4, 2004, at 2:13 AM, Geoffrey wrote:

> If some sources are generated (for example with JAXB, GUI builders, 
> ...),
> it is a good idea to keep them separated from the normal sources (to 
> be able
> to clean them etc),
> so it seems logical to me that Maven includes the option directly to 
> have
> several source directories.
> Having some sources being generated is not a valid reason to have 
> separate
> module I think.
>
> But maybe this should be looked at together with RMI stub generation
> and other binary class generators (jsp precompilation?).
> It would be nice if there is a general system to plugin plugins that
> generate sources
> or plugins that generate class files.
>
> -- 
> With kind regards,
> Geoffrey
>
> "dan tran" <da...@gmail.com> schreef in bericht
> news:c38ad92d04083007045d245b83@mail.gmail.com...
>> Roberto,
>>
>> Maven discourages from this kind of build practice, unless you are 
>> willing
> to
>> do it your self, by combining multiple source directories into one via
>> preGoal of
>> java:complile.
>>
>> The correct way is to break your project into multiple projects and
>> use Multiproject plugin to build them.
>>
>> -D
>>
>>
>>
>> On Mon, 30 Aug 2004 10:36:11 -0300, Roberto Castro
>> <ro...@cetip.com.br> wrote:
>>> Hi, in my project, java source codes are in more than one 
>>> subdirectory,
> like this:
>>> --Source
>>>     |
>>>     +-Dir1
>>>         |
>>>         +subdir1
>>>         |   + . . .
>>>         |
>>>         +subdir2
>>>             + . . .
>>> I tried to configure "project.xml" this way:
>>>        <build>
>>>                <sourceDirectory>Source/Dir1/**</sourceDirectory>
>>>
>>> But, maven was not able to find java source codes.
>>> Is there a way to compile all this codes in one subproject?
>>>        Thanks in advance for the help,
>>>
>>>     Roberto de Castro
>>>     Analista de Suporte
>>>     Cetip - Desus Rio de Janeiro
>>>     +55 21 2276-7439
>>>     mailto:robertoc@cetip.com.br
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>


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


Re: Compiling java sources codes from more than one directory

Posted by Geoffrey <jc...@hotmail.com>.
If some sources are generated (for example with JAXB, GUI builders, ...),
it is a good idea to keep them separated from the normal sources (to be able
to clean them etc),
so it seems logical to me that Maven includes the option directly to have
several source directories.
Having some sources being generated is not a valid reason to have separate
module I think.

But maybe this should be looked at together with RMI stub generation
and other binary class generators (jsp precompilation?).
It would be nice if there is a general system to plugin plugins that
generate sources
or plugins that generate class files.

-- 
With kind regards,
Geoffrey

"dan tran" <da...@gmail.com> schreef in bericht
news:c38ad92d04083007045d245b83@mail.gmail.com...
> Roberto,
>
> Maven discourages from this kind of build practice, unless you are willing
to
> do it your self, by combining multiple source directories into one via
> preGoal of
> java:complile.
>
> The correct way is to break your project into multiple projects and
> use Multiproject plugin to build them.
>
> -D
>
>
>
> On Mon, 30 Aug 2004 10:36:11 -0300, Roberto Castro
> <ro...@cetip.com.br> wrote:
> > Hi, in my project, java source codes are in more than one subdirectory,
like this:
> > --Source
> >     |
> >     +-Dir1
> >         |
> >         +subdir1
> >         |   + . . .
> >         |
> >         +subdir2
> >             + . . .
> > I tried to configure "project.xml" this way:
> >        <build>
> >                <sourceDirectory>Source/Dir1/**</sourceDirectory>
> >
> > But, maven was not able to find java source codes.
> > Is there a way to compile all this codes in one subproject?
> >        Thanks in advance for the help,
> >
> >     Roberto de Castro
> >     Analista de Suporte
> >     Cetip - Desus Rio de Janeiro
> >     +55 21 2276-7439
> >     mailto:robertoc@cetip.com.br
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >




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


Re: Compiling java sources codes from more than one directory

Posted by dan tran <da...@gmail.com>.
Roberto,

Maven discourages from this kind of build practice, unless you are willing to 
do it your self, by combining multiple source directories into one via
preGoal of
java:complile.

The correct way is to break your project into multiple projects and
use Multiproject plugin to build them.

-D



On Mon, 30 Aug 2004 10:36:11 -0300, Roberto Castro
<ro...@cetip.com.br> wrote:
> Hi, in my project, java source codes are in more than one subdirectory, like this:
> --Source
>     |
>     +-Dir1
>         |
>         +subdir1
>         |   + . . .
>         |
>         +subdir2
>             + . . .
> I tried to configure "project.xml" this way:
>        <build>
>                <sourceDirectory>Source/Dir1/**</sourceDirectory>
> 
> But, maven was not able to find java source codes.
> Is there a way to compile all this codes in one subproject?
>        Thanks in advance for the help,
> 
>     Roberto de Castro
>     Analista de Suporte
>     Cetip - Desus Rio de Janeiro
>     +55 21 2276-7439
>     mailto:robertoc@cetip.com.br
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
>

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


Re: Compiling java sources codes from more than one directory

Posted by "Jefferson K. French" <je...@frenches.org>.
Ah, I see. Thanks for the explanation, John.

On Wed, 01 Sep 2004, at 17:28:42 [GMT -0400] John Casey wrote:

> That would fail simply because it would cause his package declarations 
> to be wrong. For example, if he has:

> DIR
>    SUBDIR
>      com.myco.pkg.Class.java
>    SUBDIR2
>      com.myco.pkg.Class2.java

> then specifying <sourceDirectory>DIR</sourceDirectory> would lead to 
> javac believing the classes to be:

> SUBDIR.com.myco.pkg.Class.java
> SUBDIR2.com.myco.pkg.Class2.java

> while the actual package declarations in each java file would be 
> inconsistent with this.

> Unfortunately, the directory structure is important to javac.

> Cheers,
> -john

> Jefferson K. French wrote:
>> I guess I misunderstood the question. I thought he was trying to build
>> a single artifact, but just had his source laid out in multiple
>> subdirectories under a single parent directory. In that case, I
>> figured he could just specify the parent as the one source dir.
>> 

-- 
mailto:jeff@frenches.org



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


Re: Compiling java sources codes from more than one directory

Posted by John Casey <jd...@commonjava.org>.
That would fail simply because it would cause his package declarations 
to be wrong. For example, if he has:

DIR
   SUBDIR
     com.myco.pkg.Class.java
   SUBDIR2
     com.myco.pkg.Class2.java

then specifying <sourceDirectory>DIR</sourceDirectory> would lead to 
javac believing the classes to be:

SUBDIR.com.myco.pkg.Class.java
SUBDIR2.com.myco.pkg.Class2.java

while the actual package declarations in each java file would be 
inconsistent with this.

Unfortunately, the directory structure is important to javac.

Cheers,
-john

Jefferson K. French wrote:
> I guess I misunderstood the question. I thought he was trying to build
> a single artifact, but just had his source laid out in multiple
> subdirectories under a single parent directory. In that case, I
> figured he could just specify the parent as the one source dir.
> 
> On Wed, 01 Sep 2004, at 16:31:31 [GMT -0400] John Casey wrote:
> 
> 
>>Maven does not currently handle multiple source directories gracefully. 
>>I think you can add a preGoal of java:compile to your project's 
>>maven.xml, in which you might add your other source directories to 
>>${maven.compile.src.set} (at least, I'm pretty sure that's what the 
>>property is called - see the java:compile goal in the java plugin for 
>>more info)...
> 
> 
>>Alternately, you could subdivide your project into multiple 
>>sub-projects, and use maven's reactor feature (via the multiproject 
>>plugin) to do the trick. I prefer this approach, since the division of 
>>your source into multiple dirs implies that there is a reason for the 
>>separation...and it may be more appropriate to deal with it as separate 
>>artifacts.
> 
> 
>>HTH
>>-j
> 
> 
>>Jefferson K. French wrote:
>>
>>>Have you tried this:
>>>
>>>  <sourceDirectory>Source/Dir1</sourceDirectory>
>>>
>>>or simply
>>>
>>>  <sourceDirectory>Source</sourceDirectory>
>>>
>>>if you have other Dir diretories?
>>>
>>>  Jeff
>>>
>>>On Mon, 30 Aug 2004, at 10:36:11 [GMT -0300] Roberto Castro wrote:
>>>
>>>
>>>
>>>>Hi, in my project, java source codes are in more than one subdirectory, like this:
>>>>--Source
>>>>    |
>>>>    +-Dir1
>>>>        |
>>>>        +subdir1
>>>>        |   + . . .
>>>>        |
>>>>        +subdir2
>>>>            + . . .
>>>>I tried to configure "project.xml" this way:
>>>>       <build>
>>>>               <sourceDirectory>Source/Dir1/**</sourceDirectory>
>>>
>>>
>>>>But, maven was not able to find java source codes.
>>>>Is there a way to compile all this codes in one subproject?
>>>>       Thanks in advance for the help,
>>>
> 


Re: Compiling java sources codes from more than one directory

Posted by "Jefferson K. French" <je...@frenches.org>.
I guess I misunderstood the question. I thought he was trying to build
a single artifact, but just had his source laid out in multiple
subdirectories under a single parent directory. In that case, I
figured he could just specify the parent as the one source dir.

On Wed, 01 Sep 2004, at 16:31:31 [GMT -0400] John Casey wrote:

> Maven does not currently handle multiple source directories gracefully. 
> I think you can add a preGoal of java:compile to your project's 
> maven.xml, in which you might add your other source directories to 
> ${maven.compile.src.set} (at least, I'm pretty sure that's what the 
> property is called - see the java:compile goal in the java plugin for 
> more info)...

> Alternately, you could subdivide your project into multiple 
> sub-projects, and use maven's reactor feature (via the multiproject 
> plugin) to do the trick. I prefer this approach, since the division of 
> your source into multiple dirs implies that there is a reason for the 
> separation...and it may be more appropriate to deal with it as separate 
> artifacts.

> HTH
> -j

> Jefferson K. French wrote:
>> Have you tried this:
>> 
>>   <sourceDirectory>Source/Dir1</sourceDirectory>
>> 
>> or simply
>> 
>>   <sourceDirectory>Source</sourceDirectory>
>> 
>> if you have other Dir diretories?
>> 
>>   Jeff
>> 
>> On Mon, 30 Aug 2004, at 10:36:11 [GMT -0300] Roberto Castro wrote:
>> 
>> 
>>>Hi, in my project, java source codes are in more than one subdirectory, like this:
>>>--Source
>>>     |
>>>     +-Dir1
>>>         |
>>>         +subdir1
>>>         |   + . . .
>>>         |
>>>         +subdir2
>>>             + . . .
>>>I tried to configure "project.xml" this way:
>>>        <build>
>>>                <sourceDirectory>Source/Dir1/**</sourceDirectory>
>> 
>> 
>>>But, maven was not able to find java source codes.
>>>Is there a way to compile all this codes in one subproject?
>>>        Thanks in advance for the help,
>> 

-- 
mailto:jeff@frenches.org



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


Re: Compiling java sources codes from more than one directory

Posted by John Casey <jd...@commonjava.org>.
Maven does not currently handle multiple source directories gracefully. 
I think you can add a preGoal of java:compile to your project's 
maven.xml, in which you might add your other source directories to 
${maven.compile.src.set} (at least, I'm pretty sure that's what the 
property is called - see the java:compile goal in the java plugin for 
more info)...

Alternately, you could subdivide your project into multiple 
sub-projects, and use maven's reactor feature (via the multiproject 
plugin) to do the trick. I prefer this approach, since the division of 
your source into multiple dirs implies that there is a reason for the 
separation...and it may be more appropriate to deal with it as separate 
artifacts.

HTH
-j

Jefferson K. French wrote:
> Have you tried this:
> 
>   <sourceDirectory>Source/Dir1</sourceDirectory>
> 
> or simply
> 
>   <sourceDirectory>Source</sourceDirectory>
> 
> if you have other Dir diretories?
> 
>   Jeff
> 
> On Mon, 30 Aug 2004, at 10:36:11 [GMT -0300] Roberto Castro wrote:
> 
> 
>>Hi, in my project, java source codes are in more than one subdirectory, like this:
>>--Source
>>     |
>>     +-Dir1
>>         |
>>         +subdir1
>>         |   + . . .
>>         |
>>         +subdir2
>>             + . . .
>>I tried to configure "project.xml" this way:
>>        <build>
>>                <sourceDirectory>Source/Dir1/**</sourceDirectory>
> 
> 
>>But, maven was not able to find java source codes.
>>Is there a way to compile all this codes in one subproject?
>>        Thanks in advance for the help,
> 
> 
> 
>>     Roberto de Castro 
>>     Analista de Suporte 
>>     Cetip - Desus Rio de Janeiro 
>>     +55 21 2276-7439 
>>     mailto:robertoc@cetip.com.br 
> 
> 
> 
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>For additional commands, e-mail: users-help@maven.apache.org
> 
> 


Re: Compiling java sources codes from more than one directory

Posted by "Jefferson K. French" <je...@frenches.org>.
Have you tried this:

  <sourceDirectory>Source/Dir1</sourceDirectory>

or simply

  <sourceDirectory>Source</sourceDirectory>

if you have other Dir diretories?

  Jeff

On Mon, 30 Aug 2004, at 10:36:11 [GMT -0300] Roberto Castro wrote:

> Hi, in my project, java source codes are in more than one subdirectory, like this:
> --Source
>      |
>      +-Dir1
>          |
>          +subdir1
>          |   + . . .
>          |
>          +subdir2
>              + . . .
> I tried to configure "project.xml" this way:
>         <build>
>                 <sourceDirectory>Source/Dir1/**</sourceDirectory>

> But, maven was not able to find java source codes.
> Is there a way to compile all this codes in one subproject?
>         Thanks in advance for the help,


>      Roberto de Castro 
>      Analista de Suporte 
>      Cetip - Desus Rio de Janeiro 
>      +55 21 2276-7439 
>      mailto:robertoc@cetip.com.br 


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

-- 
mailto:jeff@frenches.org



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