File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring and command line arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring and command line arguments" Watch "Spring and command line arguments" New topic

Spring and command line arguments

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
I'd like to start an application like this

java -jar application.jar "path/conffile.conf"

and use this

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="locations">

I'd like to set the location of the propertyConfigurer to the file passed as an argument
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Instead of command line arguments, why not put the value inside the properties file?

i would also ask, why you need this functionality? I am guessing there is a different solution that would solve the reason why you need this, rather than trying something obscure. Usually, if you can't get the results quickly that you want, I tend to question why that design. There is always a simple way to accomplish stuff in Spring.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
I need to keep different configuration files to have the same process running in the same machine with different properties
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
Finally I got it right... Sorry for explaining myself so bad.

I got the desired result with this.

XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml"));
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
cfg.setLocation(new FileSystemResource(args[0]));
I agree. Here's the link:
subject: Spring and command line arguments
It's not a secret anymore!