1
--myjar.jar
--config
----appconfig.xml

I'm trying create maven based java application which can read configuration file from a relative path config\appconfig.xml

The idea here is that, the configuration can be modified without recompiling the application.

My implementation is something like this:

@Service
public class JooxXmlConfigurationServiceImpl implements XmlConfigurationService {
    @Value("${configuration.xml}")
    private String path; 
} 

Where the value is fetched from a properties file that is uder src/main/java/app-defaults.properties It works when the String path is defined as the complete address like: C:/myprojects/myapp/config/appconfig.xml but I need to set the path to be something like config/appconfig.xml

quarks
  • 33,478
  • 73
  • 290
  • 513
  • What happens when the relative path is given? I don't entirely understand where Maven comes into play. – Pace Feb 21 '13 at 02:41
  • When relative path is provided in, the error is cannot find specified file – quarks Feb 21 '13 at 10:40
  • Try `System.out.println(new File(path).getAbsolutePath());` to see how the system is resolving the file. Keep in mind, that in Java, relative paths will be resolved relative to where the application was executed from (not necessarily where the application resides) – Pace Feb 21 '13 at 16:30
  • If your jar file is a classical command-line program, pass the config\appconfig.xml as a command-line argument, a better distribute format is to write run.bat and/or run.sh to execute the java program with extra command-line arguments. Check out answer [here](http://stackoverflow.com/questions/10151458/building-complete-application-folder-with-maven) to see how Maven generate this distribute format. – yorkw Feb 28 '13 at 21:20

0 Answers0