3

I have a basic cmd program that calls a jar which has an Install class with the main method. The Install class uses a java.util.logging.config.file from its resources folder.

private static void setupLogging() { if (System.getProperty("java.util.logging.config.file") == null) { final InputStream inputStream = Install.class.getResourceAsStream("/logging.properties"); try { LogManager.getLogManager().readConfiguration(inputStream); } catch (final IOException e) { Logger.getAnonymousLogger().severe("Could not load default logging.properties file"); Logger.getAnonymousLogger().severe(e.getMessage()); } } } 

This install program belongs to a different project and I shouldn't change it. But I want to use a seperate logging.properties file from my disk (preferably from the same folder where I have the cmd program). How do I force this install program to use my logging.properties file instead of it's default one from the resources folder? Is there a way I can force this?

1 Answer 1

1

You could try this:

String yourFilePath = "./yourLogProperties.properties"; LogManager.getLogManager().readConfiguration(new FileInputStream(yourFilePath); 

Properties will be loaded from a file stored in the same folder which your app is executed.

Update:

I was searching a little bit how to pass properties thru command line and there's a pretty good explanation here. So, in your case you'll need something like this:

java -jar -Djava.util.logging.config.file="./yourLogProperties.properties" YourApp.jar 

Also you can test if it works making a simple test:

public class Tests { public static void main(String[] args) { System.out.println(System.getProperty("java.util.logging.config.file")); } } 

Running this from command line you should get the answer ./yourLogProperties.properties

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the input. But the problem here is that I still have to modify the Install class for this. I want to be able to specify the properties file thru command line, is that possible?
You're wellcome. In that case, you should take a look to this. You'll need something like java -jar -Djava.util.logging.config.file="./yourLogProperties.properties" I didn't make any test so I can't be shure if it will work. Try and let us know if so!
Thanks. That seemed to work.For some reason I was thinking that I should force the java.util.logging File to be a system property.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.