You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by mavenusr <su...@gmail.com> on 2009/07/06 21:29:52 UTC

Re: Maven - Property files Question

Dave,
Thanks a lot for your detailed explaination. I will try this out and let you
know.

one last question. If i want to update the property files, will my jar file
picksup the updates automatically or do i need to build it again?

Thanks,
Sundar

David Weintraub wrote:
> 
> There are two issues I addressed in my previous email:
> 
> Issue #1: How do you prevent those properties files from being
> packaged inside your jarfile, and Issue #2: How to make those
> properties files available as a release product.
> 
> Let's start with Issue #1: Preventing your jar file from containing
> those properties files. I gave you two recommendations:
> 
> Recommendation #1) Remove those properties files from your resources
> directory, and put them in another directory under src/main. I
> recommended calling it src/main/properties, but someone else wrote in
> and said the standard is src/main/filters (although it really isn't a
> resource filter).
> 
> This way, the standard Maven behavior will not copy those properties
> files into your jar because those properties files are not in your
> resources directory. It's simple and easy to implement.
> 
> Recommendation #2).Although the preferred way of preventing the
> properties files from being included inside your jar is to put them
> into another directory, there might be reasons beyond your control why
> this isn't possible. Maybe that's the way management has decreed, and
> you can't get them to change their mind. Maybe your developers have
> already setup their Eclipse projects and will complain bitterly if you
> try to change them.
> 
> Fortunately, there is a way in Maven to handle this. You can use
> filtering to skip over your properties files when Maven is copying in
> all the other files in your resources directory into your jar. Notice
> that this still does copy almost all of the files in your resources
> folder into your jar. All it merely does is define what you want
> copied or don't want copied to your jar file.
> 
> I gave you a link that explains exactly how to do this:
> <http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html>.
> 
> Now, let's talk about Issue #2: Distributing those properties files.
> 
> Normally in Maven, you are packaging a jar file or a warfile or an ear
> file for distribution, and this is placed into your Maven repository
> when you deploy it. However, there are times you also need to
> distribute other files with your jar or war. For example, javadocs,
> source files, or even properties files.
> 
> To do this, you use the assemblies plugin. This involves defining an
> assembly file which basically tells Maven how to package your files.
> This is completely up to you. You could create a zipfile or a tarball
> or a compressed tarball containing your properties files along with
> your jar file, or maybe you just want the properties files zipped up
> (or tarred up) as their own package.
> 
> You explain to Maven in an assembly file stored in src/main/assembly
> how to do the packaging. I gave you an example I used in my previous
> email. You have almost free reign in defining this packaging to suit
> your own needs.
> 
> Once you create an assembly file, you need to modify your pom to know
> about the assembly file (or files: You can have more than one). Again,
> I gave you an example from my own pom.xml. This goes into the
> <plugins> section of your pom.xml:
> 
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>      <artifactId>maven-assembly-plugin</artifactId>
>      <version>2.2-beta-3</version>
>      <configuration>
>          <descriptors>
>              <descriptor>src/main/assemblies/bin.xml</descriptor>
>           </descriptors>
>      </configuration>
>         <!-- Possible Execution Definition -->
> </plugin>
> 
> Now, when you do:
> 
>     $ mvn assembly:assembly
> 
> Maven will build your "assembly" which is the package that contains
> the properties files.
> 
> Of course, if you don' want to do this separate step, but want the
> assembly to be built when someone does:
> 
>     $ mvn package
> 
> you need to add a few more lines into the pom.xml to tell Maven to
> build the assemblies in the "package" phase of the life cycle. To do
> this, replace the commend line above:
> 
>      <!-- Possible Execution Definition -->
> 
> with this:
> 
> <executions>
>     <execution>
>           <phase>package</phase>
>           <goals>
>                <goal>single</goal>
>           </goals>
>      </execution>
> </executions>
> 
> This will execute the assembly:single stage in the lifecycle "package"
> phase.
> 
> Now, when you do:
> 
>     $ mvn package
> 
> Both the jar file (without the properties) and a zip or tar package
> containing the properties will be placed in the target directory.
> 
> On Fri, Jun 26, 2009 at 12:52 PM, sundar
> varadarajan<su...@gmail.com> wrote:
>> Hi Dave,
>>
>> Thanks for your reply. I m not trying to place resources folder outside
>> the
>> jar. I m trying to place the properties file that reside in resources
>> folder
>> outside the jar so that my application can pickup. What should i modify
>> in
>> my pom.xml?
>>
>> Thanks,
>> Sundar
>>
>>
>> On 6/25/09, sundar varadarajan <su...@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> I m new to Maven and I m trying to place property and config.xml files
>>> outside the Jar files. Here is my current directory
>>>
>>> Src
>>>  main
>>>   java
>>>   resources
>>> test
>>>  java
>>>   resources
>>>
>>> under java, i have all the java class files and in resources folder i
>>> have
>>> the properties and springbatch xml files.
>>>
>>> when i package the application, the property files which are under
>>> src/main/resources is also getting included. I need to place this
>>> outside
>>> the jar file so that the application can pickup when ever i make any
>>> changes
>>> to the property. currently i need to package again whenever a small
>>> change
>>> is made.
>>>
>>> please help.
>>>
>>> Thanks,
>>> Sundar
>>>
>>
> 
> 
> 
> -- 
> David Weintraub
> qazwart@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Maven---Property-files-Question-tp24214839p24361473.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: Maven - Property files Question

Posted by David Weintraub <qa...@gmail.com>.
On Mon, Jul 6, 2009 at 5:03 PM, mavenusr<su...@gmail.com> wrote:
>
> Thanks. Yes. My property files aren't part of the JAR.
>
> so again my question is, if i change the property files, will the JAR
> automically pickup the change without the need for rebuilding it?

No. If none of the files that make up your jar file are changed, the
jar file simply isn't rebuilt. Maven is really extremely good at this.
Much better than Ant.

However, if you build an assembly (that is you package that jar file
with your properties files in a tarball or a zipfile), the assembly
will be rebuilt! I mention this because I explained how to build an
assembly back in my reply to you on June 26.

That makes perfect sense. Jar file isn't rebuilt because none of the
files in it are changed. Assembly flie is rebuilt because the
properties file in it was changed.

Now, by default, Maven doesn't build assemblies on the package
lifecycle -- only the jar flie. So, by default, if you do:

    $ mvn package

And, you changed your properties file, but nothing else, the "mvn
package" won't do anything except print out a lot of garbage.

If you changed your properties file, but not any of the files that
make up the jar, and you do this:

   $ mvn assembly:assembly

The assembly will be rebuilt. The jar file won't be, but a new
assembly tarball or zip file will be rebuilt.

The only reason I'm mentioning this is that you can change Maven's
default behavior by telling Maven to build the assembly on the package
lifecycle step. Again, I mentioned how to do this in my June 26 reply
to you.

Therefore, if you changed your pom.xml file to build your assembly on
the package stage of your development lifecycle, doing this:

   $ mvn package

Will do something: It won't rebuild your jar file, but it will rebuild
your assembly.

-- 
David Weintraub
qazwart@gmail.com

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


Re: Maven - Property files Question

Posted by mavenusr <su...@gmail.com>.
Thanks. Yes. My property files are n't part of the JAR.

so again my question is, if i change the property files, will the JAR
automically pickup the change without the need for rebuilding it?


David Weintraub wrote:
> 
> On Mon, Jul 6, 2009 at 3:29 PM, mavenusr<su...@gmail.com> wrote:
>> one last question. If i want to update the property files, will my jar
>> file
>> picksup the updates automatically or do i need to build it again?
> 
> Um... I thought the properties file wasn't in your JAR.
> 
> If you put the properties file in another directory besides the
> resources directory, or if you exclude the properties files from the
> jar, but the properties files are still in the /src/main/resources
> directory, then your JAR will not rebuild if someone changes the
> properties files.
> 
> HOWEVER, if the properties files are included in your jarfile. Yes,
> your jarfile will rebuild.
> 
> Basically, whether your jar file rebuilds or not depends if any of the
> files inside the jar are changed. I've found Maven pretty good at
> keeping track of those types of things.
> 
> -- 
> David Weintraub
> qazwart@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Maven---Property-files-Question-tp24214839p24362768.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: Maven - Property files Question

Posted by David Weintraub <qa...@gmail.com>.
On Mon, Jul 6, 2009 at 3:29 PM, mavenusr<su...@gmail.com> wrote:
> one last question. If i want to update the property files, will my jar file
> picksup the updates automatically or do i need to build it again?

Um... I thought the properties file wasn't in your JAR.

If you put the properties file in another directory besides the
resources directory, or if you exclude the properties files from the
jar, but the properties files are still in the /src/main/resources
directory, then your JAR will not rebuild if someone changes the
properties files.

HOWEVER, if the properties files are included in your jarfile. Yes,
your jarfile will rebuild.

Basically, whether your jar file rebuilds or not depends if any of the
files inside the jar are changed. I've found Maven pretty good at
keeping track of those types of things.

-- 
David Weintraub
qazwart@gmail.com

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