Classpath tools : jcfind and JWhich
Deep understanding of Java classpath is something that is too often neglected. I won’t write an article about classpath, internet is full of readings about it :
- How Classes are Found at java.sun.com
- Classpath (Java) page from Wikipedia
- Classpath entry in the Java Glossary
- Java Tip 105: Mastering the classpath with JWhich
Here come JWhich and jcfind. Both are classpath reflection tools.
JWhich provides a command line interface and a Java api where jcfind only has command line interface and is written in python.
I prefer to use jcfind from the command line because it’s really faster than Which4j and the command line is more practical. In Java software, I use the JWhich API that is really easy to use. The big drawback of using Which4j from command line is that you must provide a full class name, using it’s API you can search for a class simple name.
Glassfish, Hibernate and WebServices - WSGEN Classpath
Following my quick and dirty how-to about using hibernate in glassfish I came across a small pitfall when dealing with metro webservices.
The glassfish’s wsgen classpath on Glassfish is not by domain, ie. the wsgen tool is not run in the domain class-loader.
When trying to deploy a webservice that returns an entity with a hibernate annotation, I got this following error :

Server logs showed the following trace :
/home/paul/Programs/glassfish-v2-b58g/domains/domain1/applications/j2ee-apps/ear-0.1-SNAPSHOT/lib/entities-0.1-SNAPSHOT.jar(app/model/entities/User.class):
warning: Cannot find annotation method 'value()' in type 'org.hibernate.annotations.Fetch':
class file for org.hibernate.annotations.Fetch not found
Problem encountered during annotation processing;
see stacktrace below for more information.
java.lang.NullPointerException
at com.sun.tools.ws.processor.modeler.annotation.WebServiceAP.isSubtype(WebServiceAP.java:360)
...... SNIP ......
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
error: compilation failed, errors should have been reported
Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: WSGEN FAILED
at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2
Adding the hibernate-annotations.jar file in the glassfish main lib/ directory added the necessary classes to the wsgen classpath.
Unit test JPA Entities with in-memory database
Still about Hibernate, I have several JPA Entities grouped in a Persistence Unit that I need to test. So here is another quick and dirty howto titled “Unit test JPA Entities with in-memory database”.
Here I assume you already have written your entities java classes with correct annotations.
As I’m working with embedded Derby for a year, I first tried with it but procton (thank you procton) pointed me to another lightweight RDBMS.
So, in this how-to we will set up a unit-tests dedicated persistence unit and use HSQLDB as in-memory database for unit tests.
(more…)
Building an EJB3 app using GlassFish v2, Maven2 and NetBeans 6
In an article explicitly titled Building an EJB 3.0 application using GlassFish v2, Apache Maven 2 and NetBeans IDE 6.0, Jacek Laskowski explain in detail how Netbeans 6 can be used by maven users willing to use GlassFish as an EJB3 container.
I’m currently doing these type of things with Netbeans 6 but I didn’t know it was feasible with so few command line maven invocations.
Quick and dirty howto : Use Hibernate in Glassfish V2
For my first post here I’ll write a quick and dirty howto for using Hibernate inside the Glassfish V2 container.
- Download Hibernate projects
- Put’em in the domain’s lib dir
- Change your persistence.xml file
- Enjoy
Details are following :
(more…)