Maven driven compile time ehnancement



   Just thought I'd share a small bit of Maven config to aid in enhancing persistent classes during compile time. Just add the following to your pom.xml:

     <!-- List of your packages -->

Then, in your output when performing a 'mvn clean compile' you should see something like the following (after the compile has completed):

[INFO] --- exec-maven-plugin:1.2:java (default) @ project-domain  ---

[ObjectDB 2.2.2 Enhancer]
4 persistable types have been enhanced:


Hope somebody finds it useful. I searched around for it but couldn't find a maven centric way to handle it.



Thank you for this post. Integration of enhancement into Maven is certainly useful.

I could use your example to enhance a console application but it seems that applying it on a web application might require an additional action. Please try the following:

  • Download the tutorial web application Maven project.
  • Replace the pom.xml file with the attached file.
  • Run the project from the console - using mvn package jetty:run
  • The enhancement message is shown, but the Guest.class file in the generated Guestbook.war is not enhanced (you can see that the class file size has not been changed).

Any idea what is the problem?


ObjectDB Support

For some reason, the example doesn't like 'guest.GuestListener'. I get the error:

[ObjectDB 2.2.2] Failed to generate dynamic type guest.GuestListener (error 361)

One small change - I explicitly set the class I wanted to enhance.

I attached the pom.xml you supplied with the minor change in it. I think I need some help figuring out the 361 error code however. I'm using OSX and it worked fine for me now.

This is the new output (just pasted the relevant part):

[ObjectDB 2.2.2 Enhancer]
1 persistable type has been enhanced:

Actually, your phase is a better choice than mine, as mine only does compile time - modified to actually deploy to repo!



You are right. Here is the full stack trace. The exception is thrown because the GuestListener class depends on a missing type (ServletContextListener which is not available to the Enhancer).

com.objectdb.o.UserException: Failed to generate dynamic type guest.GuestListener
 at com.objectdb.o.MSG.d(
 at com.objectdb.o.ACL.e(
 at com.objectdb.o.BCL.loadClass(
 at java.lang.ClassLoader.loadClass(
 at com.objectdb.o.SCM.w(
 at com.objectdb.o.JEW.aG(
 at com.objectdb.o.JEL.A(
 at com.objectdb.o.JEN.k(
 at com.objectdb.Enhancer.main(
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
 at java.lang.reflect.Method.invoke(
 at org.codehaus.mojo.exec.ExecJavaMojo$
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(
 at java.lang.ClassLoader.defineClass(
 at com.objectdb.o.ACL.e(
 ... 13 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
 at java.lang.ClassLoader.findClass(
 at com.objectdb.o.ACL.loadClass(
 at com.objectdb.o.BCL.loadClass(
 at java.lang.ClassLoader.loadClass(
 at java.lang.ClassLoader.loadClassInternal(
 ... 17 more

Actually the message that I saw (regarding successful enhancement) was generated by the on the fly enhancement in the listener during run, and not by the Maven enhancement that failed.

Your solution solves the problem.

ObjectDB Support

Ahh ok yes that makes sense. I've seen the issue many times in other systems that do byte code enhancements missing the external dependencies.

I guess I should have stated (everything is better retrospectively) that my pom.xml was only targeting my domain classes project. With the domain class project, I also have "Entity Listeners" so I omit those packages, but I'm a bit of a fanatic when it comes to package naming, which made it easier.

Happy to help!