Search code examples
javac#eclipseresourcebundle

Generate code from properties file


Coming from C# background, I'm used to creating a resource file Resources.resx in Visual Studio. This generates a class in the background and I can access resoures by Resources.ResourceName, which has some benefits

  • it provides auto completion ("Intellisense")
  • it generates a compiler error if a resource is renamed (instead of a runtime error)
  • I can use "Find usages" to check where the same resource is used again

AFAIK, the equivalent to a RESX file in Java is a Properties file. I can access a resource using ResourceBundle.getBundle("filename").getString("resourcename");. As you can see, the filename and the resource name are strings and

  • I don't have auto completion
  • I get runtime errors instead of compiler errors
  • I need to do a generic text search to find other usages which is not very reliable

I strongly doubt that I'm the first person who wants all the additional benefits of generated code, so

How can I generate classes from properties files in Eclipse and use it like in C#?


Solution

  • you can use jlibs library. see tutorial Internationalization made easier. BTW I am the owner of this project;

    this library provides compile time safety and uses annotations at compile time to generate java code