Tool for finding duplicate keys and values ​​in a property file

there is a tool that tells me the redundant keys and values ​​that are in my one or many property files.

+6
java java-ee internationalization
source share
6 answers

There is an Ant task, RscBundleCheck, which checks for duplicate keys in a set of resource files:

http://rscbundlecheck.sourceforge.net/

This will be an easy way to integrate duplicate property validation into the build process.

+3
source share
/** * Purpose: Properties doesn't detect duplicate keys. So this exists. * @author shaned */ package com.naehas.tests.configs; import java.util.Properties; import org.apache.log4j.Logger; public class NaehasProperties extends Properties { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(NaehasProperties.class); public NaehasProperties() { super(); } /** * @param defaults */ public NaehasProperties(Properties defaults) { super(defaults); } /** * Overriding the HastTable put() so we can check for duplicates * */ public synchronized Object put(Object key, Object value) { // Have we seen this key before? // if (get(key) != null) { StringBuffer message = new StringBuffer("Duplicate key found: " + key + " with value: " + value); message.append(". Original value is: " + (String) get(key)); log.error(message.toString()); // Setting key to null will generate an exception and cause an exit. // Can not change the signature by adding a throws as it not compatible // with HashTables put(). // // If you commented out this line, you will see all the occurrences of the duplicate key // as the put will overwrite the past encounter. // key = null; } return super.put(key, value); } } 
+4
source share

I do not know if an existing tool exists, but you should be able to write a short java program or script in a language convenient for you, which should do this as soon as possible. Then you will also receive it for future use.

A quick google search gave the following http://www.javanb.com/netbeans/1/19793.html

it has a gui tool and a script that will do this.

+1
source share

Netbeans has a line toolkit that can remove duplicates. Works fine if one property is aligned.

Moreover, sorting properties makes this file more understandable.

+1
source share

The easiest way is to simply write one: for each file and for each property in this file, place the key / value pair of the property on the map, but only after the key is not already on the map. If so, print the file name, key, and two values.

0
source share

If you are using an IDE, you can find a good tool among your plugins / functions.

Eclipse has a ResourceBundle Editor plugin that manages property files:

http://www.eclipseplugincentral.com/Web_Links-index-req-viewlink-cid-331.html

IntelliJ IDEA 8 and later can also manage property files and check for duplicate entries.

0
source share

All Articles