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);
try {
return URLDecoder.decode(url.getPath(), Charset.defaultCharset().name());
} catch (Exception e) {
e.printStackTrace();
return url.getPath();
}
}
,
instead of 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:
Why We Shouldn’t Abbreviate “Java EE 6″
Prior to today I used "JEE6" abbreviation to mean "Java EE 6". Now I have changed all "JEE6" occurrences to "Java EE 6".
The reason is that I received an email from Bill Shannon -- Java EE specification lead, who kindly asked me to use "Java EE" instead of "JEE". He provided following sources for Java naming:
- http://www.java.com/en/about/brand/naming.jsp
- http://www.theserverside.com/news/thread.tss?thread_id=35561
I really respect his opinion and appreciate his feedback. So from now on I will use "Java EE" to mean "Java EE".
JPA Persistence With GlassFish
So you want to use javax.persistence. Here is how you can configure it and run with GlassFish.
Development With GlassFish v3
GlassFish is becoming new de facto standard in Java applications. Development with new GlassFish v3 server and Eclipse now is really fast and comfortable. Server starts within a second, Java EE 6 is fully supported and hot code replacement works as it should.
Java EE 6 Injection With Dynamic Parameter
Say, you want to inject an object using @javax.inject.Inject. And you would like to pass additional dynamic parameter upon initialization. You can do the following trick.
