You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Matthew Cline <ma...@nightrealms.com> on 2018/09/04 14:15:00 UTC

Maven best practices for easily developer tweakable config file

I'm currently migrating from Ant to Maven, and am wondering how to
translate the following:

My project uses java.util.logging.  I have the logging.properties file
the app uses at a particular place.  To see what's going on I'll often
lower the level of a certain class or package in order to get more
logging output, then change it again once I'm done.  Since I'm
frequently changing it, this file isn't tracked by git.  However, I do
have a default version of logging.properties tracked by git.  If the
logging.properties which the app is pointed at is missing, then ant
copies the default version there.

However, I get the feeling that this isn't the way to do things with
Maven.  So what is the Maven way?


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


Re: Maven best practices for easily developer tweakable config file

Posted by Mirko Friedenhagen <mf...@gmx.de>.
Another possible solution could be to activate your custom logging.properties would be to use a profile

Given the following layout:
pom.xml
src/main/resources/logging.properties

Now normally the maven-resources-plugin will copy this file to target/classes/logging.properties during build and test runs and you may load it from the class-path (I did not check whether java.util.logging.config.file may do a class path lookup, though)

Add a profile to your pom.xml like this:
<profile>
    <id>local-logging.properties</id>
    <activation>
        <file>
            <exists>${user.dir}/debug-resources/logging.properties</exists>
        </file>
    </activation>
    <build>
        <resources>
            <resource>
                <directory>${user.dir}/debug-resources/</directory>
            </resource>
        </resources>
    </build>
</profile>

Create your modified logging.properties at `./debug-resources/logging.properties`, add `debug-resources/` to .gitignore

Then this should override the one from src/main/resources (not tested!)

Regards
Mirko

> Am 05.09.2018 um 20:08 schrieb Robert Scholte <rf...@apache.org>:
> 
> bq. I have the logging.properties file the app uses at a particular place.
> 
> So it seems specify the location of this file somewhere, probably with the java.util.logging.config.file property.
> How about changing the value of this property?
> 
> Robert
> 
> On Tue, 04 Sep 2018 16:15:00 +0200, Matthew Cline <ma...@nightrealms.com> wrote:
> 
>> I'm currently migrating from Ant to Maven, and am wondering how to
>> translate the following:
>> 
>> My project uses java.util.logging.  I have the logging.properties file
>> the app uses at a particular place.  To see what's going on I'll often
>> lower the level of a certain class or package in order to get more
>> logging output, then change it again once I'm done.  Since I'm
>> frequently changing it, this file isn't tracked by git.  However, I do
>> have a default version of logging.properties tracked by git.  If the
>> logging.properties which the app is pointed at is missing, then ant
>> copies the default version there.
>> 
>> However, I get the feeling that this isn't the way to do things with
>> Maven.  So what is the Maven way?
>> 
>> 
>> ---------------------------------------------------------------------
>> 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: Maven best practices for easily developer tweakable config file

Posted by Robert Scholte <rf...@apache.org>.
bq. I have the logging.properties file the app uses at a particular place.

So it seems specify the location of this file somewhere, probably with the  
java.util.logging.config.file property.
How about changing the value of this property?

Robert

On Tue, 04 Sep 2018 16:15:00 +0200, Matthew Cline <ma...@nightrealms.com>  
wrote:

> I'm currently migrating from Ant to Maven, and am wondering how to
> translate the following:
>
> My project uses java.util.logging.  I have the logging.properties file
> the app uses at a particular place.  To see what's going on I'll often
> lower the level of a certain class or package in order to get more
> logging output, then change it again once I'm done.  Since I'm
> frequently changing it, this file isn't tracked by git.  However, I do
> have a default version of logging.properties tracked by git.  If the
> logging.properties which the app is pointed at is missing, then ant
> copies the default version there.
>
> However, I get the feeling that this isn't the way to do things with
> Maven.  So what is the Maven way?
>
>
> ---------------------------------------------------------------------
> 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: Maven best practices for easily developer tweakable config file

Posted by Anders Hammar <an...@hammar.net>.
If I understand you correctly, you handle the tweaked logging configuration
file during build time (you say ant copies the file). This is not how I
woudl recommend doing this with Maven.
First, you should understand that you can use Maven (and Ant as well I
guess) for both building ("mvn clean install" for example) you app but also
as a utiliy tool (start app server, perform whatever, etc.). Here I'm
talking about building your app.

So what you should always aim for is to read resources from the class path.
By doing so you gain flexibility. For example Maven supports having a
different set for your tests (src/test/resources/) during build time. But
also, in runtime you could have a default resource (config file for
example) bundled in one of your jars and if you want to "replace" that
configuration you just add a different resource file (with the same name)
on the class path (before the jar containing the default file so that
overrides it).

/Anders

On Tue, Sep 4, 2018 at 4:15 PM Matthew Cline <ma...@nightrealms.com> wrote:

> I'm currently migrating from Ant to Maven, and am wondering how to
> translate the following:
>
> My project uses java.util.logging.  I have the logging.properties file
> the app uses at a particular place.  To see what's going on I'll often
> lower the level of a certain class or package in order to get more
> logging output, then change it again once I'm done.  Since I'm
> frequently changing it, this file isn't tracked by git.  However, I do
> have a default version of logging.properties tracked by git.  If the
> logging.properties which the app is pointed at is missing, then ant
> copies the default version there.
>
> However, I get the feeling that this isn't the way to do things with
> Maven.  So what is the Maven way?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>