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<sundarva...@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 <sundarva...@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
qazw...@gmail.com

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

Reply via email to