Run code without libs? What? Why? I had a utility class with references
to hibernate jars. This class should also be executed at the client who
doesn't have hibernate jars in its classpath. Why should it work? Well,
the utility class is determining the runtime environment. For that it
asks for the presence of "META-INF/persistence.xml". When there is
none, it assumes that it runs in the client. When there is one, it
checks the transaction type. Is it RESOURCE_LOCAL then it is executing
the local unit tests and when it is JTA it is executed on the
ApplicationServer. For checking the transaction type hibernate classes
are used.
To sum it up, when running on the client side, no hibernate is needed
and there is also none. Running in the ApplicationServer hibernate is
there and is needed. Now the question is how to avoid that the
hibernate jars are required when running on the client side?
I've put the check for the persistence.xml first so when running in
client mode, the rest of the method isn't executed. But that doesn't
solve it alone because the import statements are evaluated before the
method is ever called. So I've deleted all hibernate imports and used
fully qualified names. E.g. org.hibernate.cfg.AnnotationConfiguration
instead of AnnotationConfiguration.
And to be sure I've also put the rest of the code in method in a static
inner class. I haven't tested if this is really necessary but better
safe than sorry.