Working with Windows Registry in Java 3
jRegistryKey library actually is under LGPL. So it is suitable to be used in commercial projects too! Very simple library, that just works!
Google Will Not Participate in JavaOne
http://googlecode.blogspot.com/2010/08/update-on-javaone.html
By Joshua Bloch
Working with Windows Registry in Java 2
Ok, so the way to read registry data, which I described in previous post may be not a good idea. It is safer to rely on Windows Reg command. I wrote a simple utility to query registry using that utility.
isExistsfinds whereas registry path existsgetgets the value for specific key on certain registry path
Working with Windows Registry in Java
There are commercial and free libraries which enable a possibility to work with Windows registry from Java. For example, there is nice, simple, free, but old jRegistryKey library. The problem is that it is gpl and works with additional dll file. It is under LGPL.
However, we can read and write to Windows Registry without additional libraries and any sort of JNI. First, check out this:
http://dmi.ensica.fr/doc/Java/j2sdk-1_4_2-doc/docs/j2h/java/util/prefs/WindowsPreferences.java.html
And here are some examples how guys work with that:
http://www.davidc.net/programming/java/reading-windows-registry-java-without-jni
http://www.jroller.com/lenkite/entry/use_pure_java_to_access
A bit hacky and works only with REG_SZ. But often that is enough!
Masoud Kalali and Java EE Security
Guess who wrote recent DZone Refcardz #99. It was the same guy, who wrote GlassFish Security> book. His name is Masoud Kalali and he has own blog about Java.
java.lang.NoClassDefFoundError: Files
If you encounter the following kind of Exception, you probably
A New Book About GlassFish Security
I was granted a book from Packt about GlassFish Security. And that is something we want to improve in our products!
The book is about security in Java EE with EJB, Application Client modules and all the friends. Security in GlassFish is a central point of this book. And what is more, there are plenty of real world code and configuration samples. More information about the book can be found on dedicated page on Packt website.
Getting Path To Resource With ClassLoader
There is an easy way find a path to a resource using the ClassLoader, if desired resource is located within a project:
String getPathToResourceFile(String resourceName) {
URL url = getClass().getClassLoader().getResource(resourceName);
return url.getPath();
try {
return URLDecoder.decode(url.getPath(), Charset.defaultCharset().name());
} catch (Exception e) {
e.printStackTrace();
return url.getPath();
}
}
UPD: As correct noticed dm3 user, just calling url.getPath() will have problems with spaces in the path. Applying URLDecoder.decode will solve the problem.
Compound Key In JPA
Sometimes one needs a compound key for specifying @Entity. TopLink website says that one should provide multiple @Id and @IdClass for a composite primary key. But it actually works without specifing @IdClass too.
Hard-To-Mock Objects
What to do with objects, which are hard to mock?
For instance, you are working with org.w3c.dom. Suddenly you need a feature of extracting elements by tagname only from the first level. Since by default method getElementsByTagName returns all the elements from all levels, you decide to write your own method:
