File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring and command line arguments" Watch "Spring and command line arguments" New topic
Author

Spring and command line arguments

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 69
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">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 69
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: 69
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]));
cfg.postProcessBeanFactory(factory);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring and command line arguments
 
Similar Threads
problem with .properties file
how does ${runtime} work?
Springs property file
Property settings in spring-beans.xml at compile time
getting property value in jsp page from application.properties