Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Hey I an working on the product which is live at multiple portals. The product is developed in GWT, JAVA, Hibernate.

My question is : Whether there is any alternative of using property file in java.

My Requirement :

  1. For one property key there are multiple values in live portal for each different portal.

  2. Each time I change property file, I need to make the war again.

  3. The loading of any of the property should not be time-consuming.

Any help or suggession would be apprecialble !!!

share|improve this question
    
You are putting the property file in the war to make it in the classpath. Have you considered modifying the classpath to include things not in the war? –  MichaelT Jun 28 '13 at 19:10
    
Yes I do.. I tried to make it db driven. But that is also taking a long time load. –  Ranna Jun 28 '13 at 19:12
    
    
XML - very reliable alternative for this goal –  nazar_art Jun 29 '13 at 20:42
add comment

4 Answers 4

up vote 6 down vote accepted

I find that JSON files mapped to my own classes does wonders. A few annotations are usually all that's needed to tell the JSON libs how to serialize the class. Outside of this you pretty much live in your code for the rest of the time and get all the benefits of it (refactors, compiler checks, code complete etc)

share|improve this answer
add comment

We use XML and save configuration files in external resources (out of war/jar).

The configuration loading should not be a problem (even if you save it in database), because you don't load it frequently (don't you?). If you need update the configuration runtime, you can use file monitor API to get notified when file changed, or just a timer loop to pull data.

share|improve this answer
add comment

One option is store your configuration in a data base. This way you can change properties on the fly.

You don't actually have to install something like MySQL or PostgreSQL, you can use something really minimal such as SQLite or H2.

You can also employ a JMX bean and you can modify it also on the fly.

share|improve this answer
add comment

You may want to consider YAML

The Dropwizard framework in Java uses YAML for its external configuration. This is easier to work with than JSON since there are no braces.

You can use Jackson to unmarshal the YAML into DTOs with the Jackson Data format YAML module.

Here is an example YAML configuration for configuring the SLF4J within Dropwizard:

logging:

  level: WARN

  # Logger-specific levels.
  loggers:

    # Set specific levels
    "com.sun.jersey.api.client": DEBUG
    "com.yammer": INFO
    "org.multibit": DEBUG

  # ...
  # Settings for logging to stdout.
  console:

    # If true, write log statements to stdout.
    enabled: true

    # Do not display log statements below this threshold to stdout.
    threshold: ALL

  # Settings for logging to a file.
  file:

    # If true, write log statements to a file.
    enabled: false

    # Do not write log statements below this threshold to the file.
    threshold: ALL

    # The file to which current statements will be logged.
    currentLogFilename: /var/log/example/developer.log

    # When the log file rotates, the archived log will be renamed to this and gzipped. The
    # %d is replaced with the previous day (yyyy-MM-dd). Custom rolling windows can be created
    # by passing a SimpleDateFormat-compatible format as an argument: "%d{yyyy-MM-dd-hh}".
    archivedLogFilenamePattern: /var/log/example/developer-%d.log.gz

    # The number of archived files to keep.
    archivedFileCount: 5

    # The timezone used to format dates. HINT: USE THE DEFAULT, UTC.
    timeZone: UTC
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.